How to split string by space into words in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
 
int main() {
    char s[] = "c c++ c# php python java";
    
    char *token = strtok(s, " ");
    while (token != NULL) {
        printf("%s\n", token); 
        token = strtok(NULL, " ");
    }
     
    return 0;
}
      
     
     
      
/*
run:
       
c
c++
c#
php
python
java
  
*/

 



answered Jul 17, 2020 by avibootz

Related questions

1 answer 141 views
1 answer 133 views
3 answers 210 views
1 answer 182 views
182 views asked Jun 13, 2017 by avibootz
1 answer 198 views
1 answer 139 views
...