hi guys..
sorry for asking again regarding segmentation fault..my query consists of 12 columns in the resultset and I already called to access from row[0] until row[11]...when I try to run the program...I still got the segmentation fault...
here is my latest code:
sprintf(query1, "select a.MobileNumber, b.BillName, b.ICNew, b.Passport,"
"b.Addr, b.Addr2, b.Addr3, b.Addr4, b.Postcode, b.CountryCode, a.CreateDate, a.Source from Register as a, Profile as b"
" where a.MasterNumber = b.Number and a.Status=0");
//printf ("%s\n",query1);
if (mysql_query(&conn, query1))
{
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
{
escapeSpecialChar(row[2]);
strcpy(var1,row[9]);
if ( strcmp(var1,"MAL" ) == 0 )
{
strcpy (var1, "MALAYSIA");
strcpy(var2, var1);
}
DB2date(row[10]);
sprintf(string1,"%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], var2, newDate, row[11]);
sprintf(mobileno,"%s", row[0]);
printf ("%s\n",string1);
//printf ("Test: %s\n",mobileno);
writeLogFile(string1, mobileno);
i++;
}
}
void writeLogFile(char line2[1600], char* MobileNo)
{
char * mobile = "0192426699";
//char * mobile = MobileNo;
mobile = MobileNo;
FILE *fp;
FILE *fp2;
char len[255];
char filename[255];
int min;
int hour;
int day;
int mon;
int yr;
time_t tvec = time(0);
struct tm* dtime;
//time(&tvec);
dtime = localtime(&tvec);
min = dtime->tm_min ;
hour = dtime->tm_hour ;
day = dtime->tm_mday ;
mon = dtime->tm_mon + 1 ;
yr = dtime->tm_year +1900;
sprintf(filename,"twop_%04s""%02d""%02d""%02d""%02d"".dat",yr,mon,day,hour,min);
// Filename Format twop_yyyyMMddhhmm.dat
fp=fopen(filename, "a+");
if ( (fputs(line2, fp)) == EOF)
{
printf("error write...");
}
if ( (fputs("\n", fp)) == EOF)
{
printf("error write1...");
}
//printf ("Test2: %s\n",mobile);
UpdateStatus(mobile, line2);
bzero(line2, strlen(line2));
strcpy (line2, "1");
fclose(fp);
}
and the result something like this:
0135712114|MALIK BIN JANG|68100311355821||171, JLN KAMPUNG SERPAN LAUT,KAMPUNG SERPAN LAUT,|94600 ASAJAYA,|94600|MALAYSIA|05-12-2006|1|
Segmentation fault
it seems like, it fails to write into a file caused the segmentation fault...is it true? n how to solve this...many thanks...