#include <string.h> char *strtok(char *str1, const char *str2) str1 : 文字列 str2 : 区切り文字群
#include <stdio.h>
#include <string.h>
int main()
{
int i1;
char *pos, str1[50];
char *str;
i1 = 1;
strcpy(str1, "xyzbkxyaawwww\nccccc");
str = &str1[0];
printf("文字列 xyzbkxyaawwww\\nccccc を文字a,b,または,\\nで区切ります\n");
while ((pos = strtok(str, "ab\n")) != NULL) {
printf(" %d 番目の文字列は %s\n", i1, pos);
str = NULL;
i1++;
}
return 0;
}
文字列 xyzbkxyaawwww\nccccc を文字a,b,または,\nで区切ります 1 番目の文字列は xyz 2 番目の文字列は kxy 3 番目の文字列は wwww 4 番目の文字列は ccccc
| 菅沼ホーム | 本文目次 | 演習問題解答例 | 付録目次 | 索引 |