Thursday, July 30, 2009

How do you convert an integer to a string in C?

I'm looking for the match of the "str" Pascal function.

How do you convert an integer to a string in C?
2 different ways:





int n = 5;


char buffer[10]; /* long enough to hold your number + null */


sprintf(buffer, "%i", n);








or





itoa(number,string,radix)





radix - 10 for decimal, 16 for hex...
Reply:Use the 'itoa' funcion


void itoa(int n, char * pstr);
Reply:Int.parseInteger(somethingString)


No comments:

Post a Comment