Hi Guys,
I am trying to read each line from a file into a Sybase database table.
I'm trying to implement string tokenization so i can format each field correctly because i was getting datatype violations :S
The code I have is: -
if ((infile=fopen("datafile","r")) == NULL)
{
printf("Unable to open file 'datafile'.\n");
exit(ERREXIT);
}
printf("Inserting rows into the 'my_table' table.\n");
while ((fgets(cmdbuf,BUFLEN,infile)) != NULL)
{
printf("%s -> ", cmdbuf);
char *token = strtok(cmdbuf, ",");
while (token != NULL) {
ret = dbfcmd(dbproc,"insert into my_table \n");
printf("%s ", (ret == SUCCEED) ? "OK" : "NOK");
ret = dbfcmd(dbproc,"values(%s, %s, %s, %s, %f, %d, %f, %d) \n",cmdbuf);
}
printf("%s\n", (ret == SUCCEED) ? "OK" : "NOK");
ret = dbsqlexec(dbproc);
}
I've tried to use string tokenization. The output i get is as follows: -
$ ./inserts
inserting data
Inserting rows into the 'my_table' table.
20060714,ZZ,041510,QP,0.0000,0,15.8100,4
Memory fault
Any ideas anybody please??? :-((