C/segment fault
Expert: Narendra - 6/14/2007
QuestionHi Narendra ,Please help me in solving error comming in following code.
MYSQL_RES *result;
result = mysql_store_result(&mysql);
MYSQL_ROW row;
int i;
num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
{
unsigned long *lengths = mysql_fetch_lengths(result);
char insertquery[10000]="Insert into sunbeltsugar.listing_master_table set ";
for(i = 0; i < num_fields; i++)
{
strcat(insertquery,seller_field[i]);
strcat(insertquery,"=");
strcat(insertquery,row[i]);//segment fault
strcat(insertquery,",");
}
printf("%s",insertquery);
}
mysql_close(&mysql);
exit(0);
in above code if i printf value of row[i] then he is printing the value one by one.
But in strcat it is producing segment fault error.
Thanks in advance
Neetendra
AnswerYou have posted partial code and I have to do lot of guess work!
Anyway, here is what I think is going wrong:
You have declated row as:
MYSQL_ROW row;
So, row is not a character string.
And you are trying to use it as a string at:
strcat(insertquery,row[i]);//segment fault
I think, this is the reason for crash.