计算字符串中的单词数
// read the number of the world, space fills between the words #include<stdio.h> //#include<string.h> int func(char* character ) { int number = 0; for(int i=0; character[i] !='\0';i++) { if(character[i]!=' '&& (character[i+1]==' '||character =="\n")) { number +=1; } } return number; } int main() { FILE *f; char words[50] = "i want to fuck you "; // if words[] must initiate immediately f = fopen("C:\\users\\mike1\\desktop\\word.txt","w"); fprintf(f,"%d",func(words)); fclose(f); return 0; }