int to string+sendto
i have a variable ts which is the string length of the messages that i have to send using sendto().but i cant directly send ts as it is an integer. i need to convert ts into a char or a string so that i can send it using the sendto() function shown below
int sendto(int s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen); how can i convert it?? |
The message can be of any type...just pass &ts to sendto().
If you want to convert an int to a string then 'man sprintf'. That's one way anyway. |
sprintf help:
char *str=(char*)malloc(10); char *mess="Hello"; int num=20; sprintf(str,"Mess : %s Number: %d",mess,num) The resuling string would be str=Mess : Hello Number : 20 To concatenate a string you need to write %s and to concatenate an integer you need to write %d |
I had the same question yesterday under the title g_string_append problem. Although I didn't know that my problem was assigning a double to a string until a responder pointed it out. Here's the answer I finally found to work:
Code:
gchar *string_start; |
All times are GMT -5. The time now is 08:51 PM. |