> "USE wireless;\
> INSERT INTO master (epoch,macTS,macAddr,seqNum,sigStr,noise,attna,pck tLen)\
> VALUES(csvData.epoch, csvData.macTS, csvData.macAddr,\
> csvData.seqNum,csvData.sigStr,csvData.noise,csvDat a.attna,csvData.pcktLen)");
Well it's not going to know anything about your variable names is it?
You need to store the substituted values in a string, like
Code:
sprintf( buff, "VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
csvData.epoch, csvData.macTS, csvData.macAddr,
csvData.seqNum, csvData.sigStr, csvData.noise,
csvData.attna, csvData.pcktLen );
In fact, if these are in the same order that they were read from the file, then you've wasted your time (as already noted). All you needed to do was strip the newline off the end of the line when you read the file with fgets, and do this:
Code:
/* use return of fgets to control the loop, not feof() */
while ( fgets( line, sizeof line, ifp ) != NULL ) {
char buff[BUFSIZ];
char *p = strchr( line, '\n' );
if ( p ) {
*p = '\0'; /* remove newline */
}
sprintf( buff, "USE wireless;"
"INSERT INTO master (epoch,macTS,macAddr,seqNum,sigStr,noise,attna,pcktLen)"
"VALUES(%s)",
line );
/* Insert structure into table */
mysql_query(conn, buff );
}
The line was already full of commas, all you did was remove them just to put them back in again.
Also note the way long "strings" are folded, ie, not by using \