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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
sprintf() works like printf and writes to a string instead of standard output.
CmdrRickHunter has already provided 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;
}