LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   itoa (https://www.linuxquestions.org/questions/linux-software-2/itoa-652044/)

hai12345 06-27-2008 06:58 AM

itoa
 
hi,

any function is there in linux inceded of itoa.but it is working in windows.

theNbomr 06-28-2008 02:26 AM

sprintf() ?
--- rod.

Swagata Paul 06-28-2008 04:30 AM

yes,
u can use sprintf .......

exapmle,

main()
{

....
char ar[20];
int x=255;

sprintf(ar,"%d",x);


....

}

hai12345 06-30-2008 12:25 AM

hi thns,

i want to convert integer to string.sprintf is not working correctly.




pls help me.

paulsm4 06-30-2008 01:01 AM

Hi -

"Itoa" was popular in a number of DOS-era compilers (like Turbo C), but it was never officially a "Standard C" library function, and it was notoriously vulnerable to buffer overruns.

"sprintf()" is an alternative to "itoa()"; "snprintf()" is an even better alternative:
Code:

#include <stdio.h>

int
main ()
{
  char s[80];
  int iret = snprintf (s, sizeof (s), "%d", 100);
  printf ("string= %s, snprintf return value= %d...\n", s, iret);
  return 0;
}

'Hope that helps .. PSM

PS:
I assume when you say "itoa isn't working correctly", you probably mean that your compiler isn't recognizing it as a valid function. Again, "snprintf" is probably both a more portable and more robust solution...

theNbomr 06-30-2008 01:08 AM

Quote:

Originally Posted by hai12345 (Post 3198945)
hi thns,

i want to convert integer to string.sprintf is not working correctly.




pls help me.

Please help us to help you. 'not working correctly' is not enough information to diagnose your problem. Show us what you have tried, and explain in what way it is failing.

--- rod.


All times are GMT -5. The time now is 07:00 AM.