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 280 views
1 answer 115 views
115 views asked May 14, 2022 by avibootz
1 answer 128 views
1 answer 114 views
1 answer 105 views
1 answer 94 views
94 views asked May 14, 2023 by avibootz
...