Free Advertising | Credit Cards | Music Festival | Personal Loans | Homeowner Loans
C - Integer to String [Archive] - ZGeek

PDA

View Full Version : C - Integer to String


108
25-04-2004, 09:23 PM
I need to convert a integer into a string in C. It seems like a simple operation but I cant think of how to do it. Maybe create a function that goes /1000, then /100, then /10 and strcat's the numbers onto a string one by one, but the I sorta have the same problem :P

Is there a function that is just like the reverse of atoi?

sagit
25-04-2004, 09:32 PM
you mean like .... itoa()?

sure. its in my copy of the C programming "bible" ("The C Programming Language" [second ed] - Kernighan and Ritchie. p64)

108
25-04-2004, 09:42 PM
yeah I saw some references for itoa while googling, but its not in my copy of "C:how to porgram" which is my C bible, and there doesn't seem to be a man page on it, so I'm guessing it's some unofficial function thing that i shouldnt really use for my project.

Peach
25-04-2004, 11:10 PM
Originally posted by 108
yeah I saw some references for itoa while googling, but its not in my copy of "C:how to porgram" which is my C bible, and there doesn't seem to be a man page on it, so I'm guessing it's some unofficial function thing that i shouldnt really use for my project.

Kernighan and Ritchie wrote C. How more official do you want?

locust
26-04-2004, 04:27 AM
snprintf(buf, bufsize, "%0d", i);