输出分割的字符串

 1 #pragma warning(disable:4996)
 2 #include<stdio.h>
 3 #include<string.h>
 4 #include<stdlib.h>
 5 int main() {
 6 
 7     FILE*p = fopen("Text.txt", "r+");
 8     if (p != NULL) {
 9         printf_s("%s", "open success");
10     }
11     else {
12         printf_s("%s", "open fail");
13 
14     }
15     char buf[20];
16     fgets(buf, 19, p);
17     char sep[] = "\n\f\v\t";
18     char str[] = "now # is the time for all # good men to come  to the # aid of their country $ while you $ are a student";
19     char delims[] = "#$";//这里如果以#和空格分开,则delims[]="#  ";
20     char*result = NULL;
21     result=strtok(str, delims);
22     while (result != NULL) {
23         printf_s("%s\n", result);
24         result = strtok(NULL, delims);
25     }
26     system("pause");
27 
28 }

 

posted @ 2020-03-30 19:00  七月的四字  阅读(252)  评论(0编辑  收藏  举报