Char string[] = "I love iOS I want to make an project zpp Lanou";
char * strs[255] = {0};
int i = 0,count = 0; int wordcount = 0;
while (* (string + i)! = ' + ') {
Char temp[100] = {0};int k = 0;static int m = 0;
if (* (string + i)! = ") {
count++;
}
else{
char * str = malloc (count + 1);
wordcount++;
for (int j = I-count;j < i;j++) {
* (temp + k) = * (string + j);
k++;
}
strcpy (str, temp);
STRS[M] = str;
m++;
Count = 0;
}
if (* (string + i + 1) = = ' + ') {
char * str = malloc (count + 1); k = 0;
wordcount++;
for (int j = i-count;j <= i;j++) {
* (temp + k) = * (string + j);
k++;
}
strcpy (str, temp);
STRS[M] = str;
Free (str);
str = NULL;
}
i++; ///!!!!!!!!!!!!! In the while loop must not forget!!!!!!!!!!!!!!!!!
}
for (int i = 0; i < WordCount; i++) {
printf ("%s\t", Strs[i]);
}
This article is from the "Create a Future" blog, please be sure to keep this source http://zhaopeichina.blog.51cto.com/9782414/1601700
Saves a word in a text in an array of strings