Bootstrap

c语言作业 输入一串字符,以换行符结束输入,统计其中字符a的个数,C语言编程:输入一个以回车结束的字符串a(少于80个字符),再输入一个字符串b,统计并输出b在a中出现的...

满意答案

02ae427d08e371d7e90d5b995e828d6d.png

nike0000

2016.09.26

02ae427d08e371d7e90d5b995e828d6d.png

采纳率:42%    等级:9

已帮助:1114人

//#include "stdafx.h"//If the vc++6.0, with this line.

#include "stdio.h"

#include "string.h"

int main(void){

char a[81],b[81],k,*p,lb;

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

fgets(a,80,stdin);

printf("To enter a search string...\n");

while(fgets(b,80,stdin))//保证b不为空,否则会引发错误

if(b[(lb=strlen(b)-1)]='\0',*b=='\0')

continue;

else break;

k=0,p=a;

while(p)

if(p=strstr(p,b))

k++,p+=lb;

printf("There is(are) %d \'%s\' in the strings\n",k,b);

return 0;

}

03分享举报

;