I have a csv file that I am parsing with entries that look like:
GET,/mic-check/one.php/two/,NULL,0
POST,/mic-check/one.php,?wc-ajax=add_to_cart,0
...
GET,/mic-check/one.php/checkout/,NULL,0
GET,/mic-check/one.php/my-account/,NULL,0\0
I go through this file row by row and split each, putting the values into their respective variables. It works okay up until the absolute last line where it keeps the terminating character '%'. Example:
Method: GET
URL: /mic-check/one.php/my-account/
Query: NULL
Servers: 0%
What I would like to do, is not include this character during the parsing. Here is my code below:
int main()
{
FILE *file;
char row[MAX_LINE];
char method[MAX_COLUMN];
char url[MAX_COLUMN];
char query[MAX_COLUMN];
char servers[MAX_COLUMN];
char *tkn;
file = fopen("whitelist.csv", "r");
while(feof(file) != true) {
// Receive row
fgets(row, MAX_LINE, file);
// Parse row
tkn = strtok(row, ",");
strcpy(method, tkn);
tkn = strtok(NULL, ",");
strcpy(url, tkn);
tkn = strtok(NULL, ",");
strcpy(query, tkn);
tkn = strtok(NULL, ",");
strcpy(servers, tkn);
// Use the variables
}
return 0;
}