Link to home
Start Free TrialLog in
Avatar of jameswalt
jameswalt

asked on

int to String C Question

Hi,

   How do I convert an integer to a string? Easiest coded example will be awarded.

I have an integer, p

want to convert p to string and send it using the following send command:

send(s, STRING, strlen(STRING), 0)

where s is a socket and STRING is int p converted to a string.
Please provide the correct code to send this int converted to string, as short and precise as possible.

SOLUTION
Avatar of ankuratvb
ankuratvb
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here's an example:
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
   int number = 12345;
   char string[25];

   itoa(number, string, 10);
   printf("integer = %d string = %s\n", number, string);
   return 0;
}
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jameswalt
jameswalt

ASKER

Getting undefined symbol. I have the files included.
Yeah,you can use sprintf() in case you dont have itoa().

sprintf() works like printf and writes to a string instead of standard output.

CmdrRickHunter has already provided an example.