#include<stdio.h>
#include<ctype.h>
#include<malloc.h>
#include<string.h>
#define N 20
#define M 30
int str_parase(char * res, char word[][N])
{
int i, wordLen=0, wordNum=0;
char temp[20];
int n = strlen(res);
for (i = 0; i < n; i++)
{
if (res[i] == ' ' || res[i] == '\t')
{
if (wordLen != 0)
{
temp[wordLen] = '\0';
strcpy_s(word[wordNum], temp);
wordNum++;
wordLen = 0;
}
}
else
{
temp[wordLen++] = res[i];
}
}
if (word != 0)
{
temp[wordLen] = '\0';
strcpy_s(word[wordNum], temp);
wordNum++;
wordLen = 0;
}
return wordNum;
}
int main()
{
char b[M][N];
int num;
int i;
char s[] = "what are you doing ?";
num = str_parase(s, b);
if (0 == strcmp(b[0], "what"))
printf("OK\n");
printf("num : %d \n", num);
for (i = 0; i < num; i++)
printf("%s\n", b[i]);
while (1);
return 0;
}
字符串解析为单词
最新推荐文章于 2019-09-14 04:40:08 发布