Segmentation Fault in C Program

Reason for error:
– Declared a string sql[200]
– Did sprintf(sql, “……”, variables);
– String in sql crossed 200 characters.
Therefore, program memory space got corrupt leading to above segmentation fault in other variables.

Overcome by debugging
– Watch variables for statement where sprintf was there, to see if any memory variable pointers were changed.
– Found that at sprintf, the value for *button was getting chan ged.
Increased size of string sql to 1000 and problem got solved.