c语言中s所指数值,下列给定程序中,函数fun的功能是:从s所指字符串中,找出t所指字符串的个数作为函数值返回。例如,当s所指字符串中的内容为“abcdabfab”,t所指字符串的内容为“ab”,则函...

下列给定程序中,函数fun的功能是:从s所指字符串中,找出t所指字符串的个数作为函数值返回。例如,当s所指字符串中的内容为“abcdabfab”,t所指字符串的内容为“ab”,则函数返回整数3。

请改正程序中的错误,使它能得出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

/**********code.c**********/

#include

#include

#include

#include

int fun(char *s, char *t)

{

int n;char *p, *r;

n=0;

while(*s)

{

p=s;

r=t;

while(*r)

/**********found**********/

if(*r==*p){r++; p++}

else break;

/**********found**********/

if(r=='\0')

n++;

s++;

}

return n;

}

void main()

{

char s[100],t[100]; int m;

system("CLS");

printf("\nPlease enter strings:");

scanf("%s",s);

printf("\nPlease enter substrings:");

scanf("%s",t);

m=fun(s,t);

printf("\nThe result is:m=%d\n", m);

}

/**********-code.c**********/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值