Programming Reference/Librarys
Question & Answer
Q&A is closed
Function strtok breaks a string (str1) into individual strings based on the so-called token. The string is separated by one delimiter (str2). “str2” may contain multiple tokens, e.g. str2 = “\ n” (ie separation in space, comma, New Line, Point).
/* * strtok example code * http://code-reference.com/c/string.h/strtok */ #include <stdio.h> #include <string.h> int main(void) { // this example shows how you can easy parse a csv file in c char csvcontent[] = "row;of a csv file; with cool content;parse csv in c"; char seperator[] = ";"; char *string; int i=1; string = strtok(csvcontent, seperator); while(string != NULL) { printf("column %d = %s\n", i++, string); string = strtok(NULL, seperator); } return 0; }
column 1 = row
column 2 = of a csv file
column 3 = whith cool content
column 4 = parse csv in c