题2:统计字符串中各个单词出现的次数,最多100个英文单词。如:"I am am aa bb cc bb aa",则I:1,am:2,aa:2,bb:2,cc:1
方法一:
#include <stdlib.h> #include <stdio.h> #include<string.h> void Count_Word(char* buf); int main() { char* word="I am am aa bb cc bb aa"; Count_Word(word); return 0; } void Count_Word(char* buf) { int m=0; if(buf==NULL) printf("ERROR"); char* tmp=NULL; char* words[100]; //指针数组:数组里存放的是指针,指针指向字符串 int count[100]; memset(words,0,100); //void *memset(void *s, char ch, size_t n);将s中前n个字节用字符ch替换并返回s for(int n=0;n<100;n++) count[n]=0; tmp=buf; while(*buf!='