{{keywords>wiki library source code example reference}} ====== strtok ====== #include char *strtok(char *str1, const char *str2); ===== description of strtok ===== 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 C Sourcecode Example ===== /* * strtok example code * http://code-reference.com/c/string.h/strtok */ #include #include 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; } ==== output of strtok c example ==== column 1 = row column 2 = of a csv file column 3 = whith cool content column 4 = parse csv in c