Write this sectionProgramOne student asked me how the send function in Winsock sent an int value. I checked the send prototype.
Int send (socketS,Const char far* Buf,IntLen,IntFlags);
WhereThe second parameter must be a string pointer.. So I thought about howConverts an int value to a string.As a result, the following section is written:Code.
/***************************************. C * One program which contains ITOA (,); strlen (..); functions. * In order to implement 'int' to 'Char *'*************************** **************************************** * ***** // # include <stdio. h> # include <stdlib. h> // int main () {int num = 12345; char STR [10]; int I = 0;/** TianYe-2012-5-26 * char * ITOA (INT value, char * string, int Radix); * ITOA () converts an integer to a string. * return value: pointer to the string. */ITOA (Num, STR, 10); printf ("int_1 = % d, STR = % s \ n", num, STR ); printf ("Len = % d \ n", strlen (STR); // num = 789; ITOA (Num, STR, 10 ); printf ("int_2 = % d, STR = % s \ n", num, STR); While (STR [I]! = '\ 0') {printf ("char = % C \ n", STR [I]); I ++;}/** TianYe-2012-5-26 * strlen (STR) -calculate the length of the STR string. */Printf ("Len = % d \ n", strlen (STR); // return 0 ;}
the code execution result is as follows: