"C언어 단어 추출"의 두 판 사이의 차이

25번째 줄: 25번째 줄:
         printf("[%d] %s\n", i, words[i]);
         printf("[%d] %s\n", i, words[i]);
     }
     }
 
    // [0] Hello
    // [1] World
    // [2] Foo
    // [3] Bar 
   return 0;
   return 0;
}
}
// [0] Hello
 
// [1] World
// [2] Foo
// [3] Bar
</source>
</source>



2017년 11월 23일 (목) 23:31 판

1 개요

#include <stdio.h>
#include <string.h>

#define NUMBER_OF_STRINGS   200
#define STRING_LENGTH       80

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

    int count = 0;
    char *token;
    token = strtok(str, seps);
    while( token != NULL ) {
        strcpy( words[count], token );
        count++;
        token = strtok(NULL, seps);
    }
    
    for(int i=0; i<count; i++) {
        printf("[%d] %s\n", i, words[i]);
    }
    // [0] Hello
    // [1] World
    // [2] Foo
    // [3] Bar   
   return 0;
}

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}