format specifier for short integer
- by cateof
I don't use correctly the format specifiers in C. A few lines of code:
int main()
{
char dest[]="stack";
unsigned short val = 500;
char c = 'a';
char* final = (char*) malloc(strlen(dest) + 6);
snprintf(final, strlen(dest)+6, "%c%c%hd%c%c%s", c, c, val, c, c, dest);
printf("%s\n", final);
return 0;
}
I want my executable to print aa500aastack and not aa500aasta
Why I am loosing 2 byte? What is the correct format specifier for an unsighed short integer?
thanks.