Thursday, July 30, 2009

How to convert integer to string in C/C++?{Try to tell in ANSI GCC, but TC command would also do}?

char str[10];


int i=32760;


sprintf(str,"%d",i);

How to convert integer to string in C/C++?{Try to tell in ANSI GCC, but TC command would also do}?
Use ITOA function: http://www.itlnet.net/programming/progra...





EDIT: Non-standard, but readily available in TC (see question). I'm sure of it.
Reply:Both of the above answers are correct, however, as the Wikipedia points out, itoa is not part of the C standard -- it is usually found in stdlib.h but it is not part of the C standard.





sprintf (String PRINT Format) is one of several related functions (like vprintf) which are in stdio.h. This one "prints" formatted output to any char array large enough to hold it. And terminates it with a 0 char as any good old fashioned C ASCIIZ string should be. It may not seem like it is part of the standard but it is. And teachers seem not to like it as much.


;-)


No comments:

Post a Comment