C언어 단어 추출

1 개요[ | ]

C
CPU
0.1s
MEM
18M
0.2s
Copy
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define NUMBER_OF_STRINGS 200

int main() {
    char *words[NUMBER_OF_STRINGS];
    char seps[] = "[]'`_*?0123456789()\",.! -:;/\t\n";
    char str[] = "  'Hello\tWorld!'  Foo\nBar  ";

    int count = 0;
    char *token;
    token = strtok(str, seps);
    while( token != NULL ) {
        words[count] = malloc(strlen(token)+1);
        strcpy( words[count], token );
        count++;
        token = strtok(NULL, seps);
    }
    
    for(int i=0; i<count; i++) {
        printf("%d: [%s]\n", i, words[i]);
    }

   return 0;
}
0: [Hello]
1: [World]
2: [Foo]
3: [Bar]

2 같이 보기[ | ]