LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   convert integers to ascii (https://www.linuxquestions.org/questions/programming-9/convert-integers-to-ascii-14246/)

raven 02-14-2002 09:02 AM

convert integers to ascii
 
hello

does somebody know if there is a built-in function in c to convert an integer vaue into a "string"?

i need to store for example 234 in this form:

char *value;

the result then shoud be:
*(value+0)=2
*(value+1)=3
*(value+2)=4

any ideas? or do i have to write my own function to do this???

thanks

raven

Tonneman 02-14-2002 11:29 AM

You need your output string to be already allocated, then do something like:

int Number = 234;

char Value[MAX_SIZE];

sprintf(Value, "%d", Number);

Mik 02-15-2002 02:47 AM

The function itoa is also made specifically for converting integers to a character array.

Tonneman 02-15-2002 03:32 AM

Quote:

Originally posted by Mik
The function itoa is also made specifically for converting integers to a character array.
Ach! I knew there was one that did that. But I couldn't remember what it was, and I could only find atoi.


All times are GMT -5. The time now is 05:03 PM.