User Tools

Site Tools


Programming Reference/Librarys

Question & Answer

Q&A is closed



#include <stdlib.h>
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
#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;

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

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/string.h/strtok.txt · Last modified: 2024/02/16 01:06 (external edit)

Impressum Datenschutz