请教C语言指针的题目?大佬们帮帮忙!跪谢!!!

2024-11-23 08:59:07
推荐回答(1个)
回答1:

如果正确,望采纳,有问题续问。

代码文本:

#include "stdio.h"

#include

int fun(char *ps,char *pw,int *pt){

char *p;

int k;

p=ps,k=0;

while(p=strstr(p,pw))

pt[k++]=p++-ps;

return k;

}

int main(int argc,char *argv[]){  

char s[300],w[23];

int n,t[50],i;

printf("Please enter a text...\n");

fgets(s,300,stdin);

printf("Please enter a word to find...\nThe word: ");

scanf("%22s",w);

printf("\nThe %d time(s):\n",n=fun(s,w,t));

for(i=0;i

printf("For the %d time in %d position\n",i+1,t[i]);

return 0;

}