#include <>int lookup(char *str, char *key);main(){ char str[1024] = "asdfjad asdfh adsf adsf adsf adf adsfasdfkjasdf andsf akdf sdkf" char key[32]; int pos[100]; printf("输入要查询的单词: "); scanf("%s", key); lookup(str, key, pos); printf("共重复了%d次\n,位置分别是:", pos[0]); for(i = 1 ; i <= pos[0]; i ++) { printf("%d “, pos[i]); } printf("\n");}int lookup(char *str, char *key, int pos[]){ int i, j; pos[0] = 0; /* 记录重复次数 */ for(i = 0; i < strlen(str); i ++) { if(key[0] == str[i]) { for(j = 1; j < strlen(key); j ++) { if(key[j] != str[i+j]) break; } if(j == strlen(key)) { /* found */ pos[0] ++; pos[pos[0]] = i; i += j-1; } } }}