How to split a string by 1 or more white spaces in C

1 Answer

0 votes
#include <stdio.h> 
#include <string.h> 

int main(void)
{
    char s[] = "c  c++  \n    c#  \r java  \t  python";
    char delimiters[] = " \n\r\t";
    char* p;

    p = strtok(s, delimiters);
    while (p != NULL) {
        puts(p);
        p = strtok(NULL, delimiters);
    }

    return 0;
}



/*
run:

c
c++
c#
java
python

*/

 



answered Jul 1, 2024 by avibootz

Related questions

...