strtokだとコンパイラに怒られるので、ここは素直にMSの指示に従おう。
01 | #include <stdio.h> |
02 | #include <string.h> |
03 |
04 | #ifndef null_ptr |
05 | #define null_ptr 0 |
06 | #endif |
07 |
08 | char str[] = "asdc,fghm jkl;" ; //分割したい文字列 |
09 | char *delim = ", " ; //デリミタ(複数渡せる)ここではカンマと空白 |
10 | char *ctx; //内部的に使用するので深く考えない |
11 |
12 | //実行例 |
13 | int main() |
14 | { |
15 | char *next = strtok_s(str, delim, &ctx); |
16 | while (next){ |
17 | printf ( "%s\n" , next); |
18 | next = strtok_s(null_ptr, delim, &ctx); |
19 | } |
20 | // 出力結果 -------------------------------- |
21 | // >> asdc |
22 | // >> fghm |
23 | // >> jkl; |
24 | return 0; |
25 | } |
0 件のコメント:
コメントを投稿