How to use the strtok() to split a string s[] into tokens in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
 
int main(void)
{
	char s[] = "The C - programming, language.";
	char *p;
  
	p = strtok(s, " ,.-");
	while (p != NULL)
	{
		printf ("%s\n", p);
		p = strtok(NULL, " ,.-");
	}
     
    return 0;
}

 
/* 
run:

The
C
programming
language

*/

 



answered Feb 16, 2016 by avibootz

Related questions

2 answers 286 views
1 answer 121 views
121 views asked May 14, 2022 by avibootz
1 answer 142 views
1 answer 129 views
1 answer 115 views
1 answer 104 views
104 views asked May 14, 2023 by avibootz
...