#include <stdio.h>
int sprintf(char *str, const char *format, ...);
#include <string.h>
#include <stdio.h>
int main()
{
char str[12]="Hello world";
int num = 0x12345678;
sprintf(str, "%8x", num);
printf("str is %s and the length of str is %ld\n", str, strlen(str));
return 0;
}
The output result:
C_exec$ gcc test_sprintf.c
C_exec$ ./a.out
**str is 12345678 and the length of str is 8**
C_exec$