What’s wrong with the following piece of code that the program crashes – give segmentation fault. I am using gcc.
uint8_t result = 1
InsertRow("Name","Details of work",result);
void InsertRow(char *Name, char *Description,uint8_t Result)
{
char Buffer[500];
if(Result==1)
sprintf(Buffer,"<tr><td>%s </td> <td> %s </td> <td> %s </td></tr>",Name,Description,Result);
}
You’re using the
%sformatting specifier for an argument of typeuint8_t, this should be%u, and you should cast the value tounsigned intto match. This saves you from having to care about the exact type and adjust the formatter (as commenters suggest).Also, it’s hard for us to know that the buffer is large enough, of course. If you have it, you can use
snprinf()to avoid this.