473,804 Members | 2,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

convert int to char

Does anyone have a function or procedure for converting integers to
character strings?

Thank you,
John
Nov 14 '05
30 8687
Chris Croughton <ch***@keristor .net> writes:
On Mon, 11 Apr 2005 19:17:45 +0200, Emmanuel Delahaye
<em***@YOURBRAn oos.fr> wrote:
Neil Kurzman wrote on 11/04/05 :
itoa() exists, I assume it is non-standard??
If it not standard, it doesn't exist :-)


That's one of the stupid attitudes which encourages people to label
comp.lang.c as a bunch of ego-wankers.


I agree that the attitude can go a bit too far sometimes. For
example, it's absurd to assert that the open() and close() functions
don't exist. They do exist as part of the POSIX standard (and a
non-POSIX program is free to define functions, or other entities, with
the same names). But the POSIX-specific functions are off-topic here
in comp.lang.c.
Of course itoa() exists on many systems and in many program sources. It
simply isn't On Topic for this newsgroup, and can't be used portably.


Does it really? I just checked several systems I have access to; none
of them define an itoa() function.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #21
Christopher Benson-Manica wrote:
Chris Croughton <ch***@keristor .net> spoke thus:
Of course itoa() exists on many systems and in many program
sources. It simply isn't On Topic for this newsgroup, and can't
be used portably.


But can it be written portably? That's a valid question here.


I'll answer that as soon as you define exactly what it does. I put
up a valid implementation yesterday or so, didn't you like it? I
believe it reliably converted an 'i' to an 'a', and was completely
portable.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #22
CBFalconer <cb********@yah oo.com> spoke thus:
I'll answer that as soon as you define exactly what it does. I put
up a valid implementation yesterday or so, didn't you like it? I
believe it reliably converted an 'i' to an 'a', and was completely
portable.


Sorry for implying otherwise...

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #23
On Mon, 11 Apr 2005 21:28:08 GMT, Keith Thompson
<ks***@mib.or g> wrote:
I agree that the attitude can go a bit too far sometimes. For
example, it's absurd to assert that the open() and close() functions
don't exist. They do exist as part of the POSIX standard (and a
non-POSIX program is free to define functions, or other entities, with
the same names). But the POSIX-specific functions are off-topic here
in comp.lang.c.


Yes, exactly. It's one thing to say "Those functions are off-topic
here, because they aren't part of Standard C, try somewhere like
comp.unix.progr ammer", and a different one to say a blanket "it doesn't
exist". The latter will just get the OP's response "Yes it does!".
Of course itoa() exists on many systems and in many program sources. It
simply isn't On Topic for this newsgroup, and can't be used portably.


Does it really? I just checked several systems I have access to; none
of them define an itoa() function.


Borland defines it for Win32, and says under 'portability' that it's a
Win32 function. I remember it being on DOS as well. I've also seen it
re-implemented in code for *ix software, so it 'exists' on those systems
even if not in a system library.

Chris C
Nov 14 '05 #24
Chris Croughton wrote on 11/04/05 :
On Mon, 11 Apr 2005 19:17:45 +0200, Emmanuel Delahaye
<em***@YOURBRAn oos.fr> wrote:
Neil Kurzman wrote on 11/04/05 :
itoa() exists, I assume it is non-standard??


If it not standard, it doesn't exist :-)


That's one of the stupid attitudes which encourages people to label
comp.lang.c as a bunch of ego-wankers.


A serious lack of humour... Get a life...

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

..sig under repair

Nov 14 '05 #25
In article <mn************ ***********@YOU RBRAnoos.fr>,
Emmanuel Delahaye <em***@YOURBRAn oos.fr> wrote:
Chris Croughton wrote on 11/04/05 :
On Mon, 11 Apr 2005 19:17:45 +0200, Emmanuel Delahaye
<em***@YOURBRAn oos.fr> wrote:
Neil Kurzman wrote on 11/04/05 :
itoa() exists, I assume it is non-standard??

If it not standard, it doesn't exist :-)


That's one of the stupid attitudes which encourages people to label
comp.lang.c as a bunch of ego-wankers.


A serious lack of humour... Get a life...


But that *is* clc.

A sense of humor is OT here. And, as with most OT posts, the regulars will
generally be more than willing to supply names of other newsgroups where
what you seek is on topic. For example, I suggest: alt.folklore.ur ban.

Nov 15 '05 #26
> From: "John Carroll" <or*******@yaho o.com>
Does anyone have a function or procedure for converting integers to
character strings?


Your question is hopelessly vague. There are all sorts of mappings from
integers to character strings. Here are just a few (with quote marks
omitted):

Arabic numerals:
Decimal: 42
Octal: 52
Hexadecimal: 2A
Binary: 101010
Unary with stop bit: 111111111111111 111111111111111 1111111111110
Tally:
Original: IIIII IIIII IIIII IIIII IIIII IIIII IIIII IIIII II
Old: <http://www.rawbw.com/~rem/AsciiArt/TallyOldAA.txt>
New: <http://www.rawbw.com/~rem/AsciiArt/TallyNewAA.txt>
Roman numerals:
Old: XXXXII
New: XLII
Cardinal:
English: forty-two
German: zwei und vierzig (Note: AltaVista Babelfish gets this wrong!)
French: quarante deux
Spanish: cuarenta dos
Portuguese: quarenta dois
Ordinal:
English: forty-second
French: quarante seconde
Spanish: cuarenta segundos
Portuguese: quarenta segundos
German: (Babelfish says vierzig zweites, but I don't believe it's correct.)
Traditional base 12:
English: three dozen and six
French: trois douzaines et six
German: drei Dutzend und sechs
Spanish: tres docenas y seises
Traditional by Abraham Lincoln:
English: two score and two

So do you want a single function capable of all those conversions, or what?

Oh, you just want a single character? That's not possible because the
range of integers is larger than the range allowed for a single
character, whether a single byte (US-ASCII or Latin-1) or double byte
(subset of UniCode). If you restrict the range of integers to what
will fit in a single byte, then you have your choice of Latin-1 or
several other system-dependent codes. If you restrict the range of
integers to what will fit in 7 bits, you have your choice of US-ASCII
or EBCDIC. (C provides support only for US-ASCII, via a "cast".) If you
restrict the range of integers to 0 thru 35, you have extended
IBM-hexadecimal: 0123...9ABCDE.. .XYZ. If you restrict the range to only
0 thru 15, C provides support via sprintf(&ch, "%x", intval).
Nov 15 '05 #27
In article <RE************ ***@Yahoo.Com>,
Robert Maas, see http://tinyurl.com/uh3t <re*****@Yahoo. Com> wrote:
From: "John Carroll" <or*******@yaho o.com>
Does anyone have a function or procedure for converting integers to
character strings?


Your question is hopelessly vague. There are all sorts of mappings from
integers to character strings. Here are just a few ...


and the void would be calling
--
7842++
Nov 15 '05 #28
re*****@Yahoo.C om (Robert Maas, see http://tinyurl.com/uh3t) wrote:
# > From: "John Carroll" <or*******@yaho o.com>
# > Does anyone have a function or procedure for converting integers to
# > character strings?

char b[sizeof(int)*CHA R_BIT/3+1];
sprintf(b,"%d", int_value);

The formatted integer is in b.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
GERBILS
GERBILS
GERBILS
Nov 15 '05 #29
In article <RE************ ***@Yahoo.Com>,
Robert Maas, see http://tinyurl.com/uh3t <re*****@Yahoo. Com> wrote:
Your question is hopelessly vague. There are all sorts of mappings from
integers to character strings. Here are just a few Traditional base 12:
English: three dozen and six


It seems to me that more traditional would be
"three and a half dozen"

--
History is a pile of debris -- Laurie Anderson
Nov 15 '05 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
22072
by: Brad Moore | last post by:
Hey all, I'm getting the following compiler error from my code. I was wondering if anyone could help me understand the concept behind it (I actually did try and compile this degenerate example). int foo(const char* argv) { return 0; } int main(int argc, char* argv) {
7
66770
by: MilanB | last post by:
Hello How to convert char to int? Thanks
2
8185
by: Alper Akcayoz | last post by:
Hello Esteemed Developpers I would like to thank you in advance for your sincere responses I am a fresh Visual C++ .NET Developer. Can you kindly guide me for How to Convert char* to System::String
1
19204
by: Elioth | last post by:
Hi... I need to know how to convert Char Array to Byte Array and vice-versa in VB 2K5 Thanks for all help. Elioth
2
94063
by: Joah Senegal | last post by:
Hello I need to convert a chat to a string... but I don't know how to do this. i;ve searched the internet but I've only find some code to convert char * to string or char to string.... but I just need char to string. Anyone knows how to do this ? thanks!!!!
3
5360
by: simon | last post by:
I am a fresh Visual C++ .NET Developer. Can you kindly guide me for How to Convert char to System::String I am using windows forms and trying to set a text value referencing the method className() of an object of class HetConvert (my own) this returns a char - which as you can see from the code below I am trying to pass to label1->Text - but this expects a String^ any clues anyone
2
4163
by: Rasheed | last post by:
Hi, i have a char pointer buffer which will hold the bitmap buffer, So i need to convert char *buffer as a bitmap. becuase when i draw on the Dialog using char *buffer. Nothing will be dispalyed. So kindly can any body help me how to convert char *buffer to bitmap. i want the solution in C++
1
2780
by: helios | last post by:
Hi all, I'm resolved problem. and I want anybody need me that convert char to array bits char ConvertChar2ArrayBit(char ch) { char Bits; .... return Bits; } for example: A after converted: 10000010
3
19875
by: mamul | last post by:
Hi please some one can help me. how to convert char * to string? i have take char *argv from command line and want to pass to a function as string object(string str) i want to first convert argv to string object of type str, then pass to function(). please help me how to convert this
3
6755
by: DaveRook | last post by:
Hi I've had a few error messages with this I don't understand why. It works fine in a Windows Form, but now moving it to a website, it's not working. I don't have the option to count the lines as I did with Windows Forms so I assume the best way is to use the split method. However, the split method only returns Character Arrays, and I want a string, so am calling the split from the Text.RegularExpression namespace. I am trying to split...
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10311
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.