How to split a string into words in C

2 Answers

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

 



answered Feb 3, 2017 by avibootz
0 votes
#include <stdio.h> 
#include <string.h> 
 
int main(void)
{   
    char s[] = "-c, c++.. c# -java ,php.";
    char *p;
     
    p = strtok (s, " -.,");
    while (p != NULL)
    {
        puts(p);
        p = strtok (NULL, " -.,");
    }
     
    return 0;
}
 
       
/*
run:
    
c
c++
c#
java
php
   
*/

 



answered Feb 3, 2017 by avibootz

Related questions

1 answer 139 views
1 answer 156 views
156 views asked Dec 25, 2021 by avibootz
1 answer 165 views
165 views asked Dec 25, 2021 by avibootz
1 answer 191 views
191 views asked Jul 17, 2020 by avibootz
1 answer 132 views
1 answer 189 views
189 views asked Dec 25, 2021 by avibootz
...