Programmation Avancée en C


strtok.c

00001 #include <stdio.h>
00002 #include <string.h>
00003 
00004 #define MAX_STRING_SIZE 80
00005 #define SEP_CHARS       " .,:;?!\"\n"
00006 
00007 int main()
00008 {
00009     char  s[MAX_STRING_SIZE];
00010     printf("Entrez une phrase : \n");
00011     fgets(s, MAX_STRING_SIZE, stdin);
00012     char * word = strtok(s, SEP_CHARS);
00013     while (word != NULL) {
00014         printf("Token : |%s|\n", word);
00015         word = strtok(NULL, SEP_CHARS);
00016     }
00017     return 0;
00018 }
00019