Hi all,
I try to compile my program and got this kind of error:
test6.c: In function `main':
test6.c:46: too many arguments to function `mysql_query'
Here is my code:
int main(int argc, char *argv[])
{
char string1[1600], string2[1600], query[1600], mobileno[50];
int i, j, len;
FILE *fp2;
mysql_init(&conn);
/* Connect to database */
if (!mysql_real_connect(&conn, host, user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(&conn));
exit(0);
}
/* send SQL query */
if (mysql_query(&conn, "select a.MobileNumber, a.MasterNumber , a.MasterAccNo, b.Addr, b.Addr2, b.Addr3, b.Addr4, b.Addr5, b.Addr6, b.Addr7, b.Addr8, b.Postcode, b.CountryCode, b.BillName, b.CorrName, b.ICNew, b.ICOld, b.Passport from Register as a, Profile as b where a.MasterNumber = b.Number and a.Status=0 and a.MasterNumber = '%s'", masterno)) {
fprintf(stderr, "%s\n", mysql_error(&conn));
exit(0);
}
res = mysql_use_result(&conn);
/* output fields 0, 1 and 2 of each row */
while ((row = mysql_fetch_row(res)) != NULL)
{
if (i==11)
{
timebuffer();
i=1;
bzero(string1, sizeof(string1));
}
else
{
sprintf(string1,"%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|", row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12], row[13], row[14], row[15], row[16], row[17], row[18]);
printf ("%s\n",string1);
writeLogFile(string1, mobileno);
i++;
}
}
/* Release memory used to store results and close connection */
mysql_free_result(res);
mysql_close(&conn);
return 0;
}
i try to alter the code to become like this:
/* send SQL query */
bzero(query1, sizeof(query1));
sprintf(query1, "select a.MobileNumber, a.MasterNumber , a.MasterAccNo, b.Addr, b.Addr2, b.Addr3, b.Addr4, b.Addr5, b.Addr6, b.Addr7, b.Addr8, b.Postcode, b.CountryCode, b.BillName, b.CorrName, b.ICNew, b.ICOld, b.Passport from Register as a, Profile as b where a.MasterNumber = b.Number and a.MasterNumber = '%s' and a.Status=0", MasterNo);
printf ("%s\n",query1);
if (mysql_query(&conn, query1))
{
fprintf(stderr, "%s\n", mysql_error(&conn));
exit(0);
}
at the end..when i try to run the program, i got "segmentation fault"
Please help me..many thanks