江西省2级c语言上机改错

[复制链接]
查看11 | 回复3 | 2008-11-27 05:31:36 | 显示全部楼层 |阅读模式
计算字符串中子串出现的次数,改正程序中的2个错误,使程序能输出正确的结果。不要改动main函数,不得删行减行
ge342.c;
#include"string.h"
#include"stdio.h"
main()
{char str1[20],str2[20],*p1,*p2;
int sun=0;
printf("please input two strings\n");
scanf("%s%s",str1,str2);
p1=str1; p2=str2;
while(*p1!='\0')
{
if(*p1= =*p2||*p2!='\0')
{p1+ +;
p2+ +;}
}
else
p2+ +
if(*p2= ='\0')
Sum+ +;
p2=str2
}
printf("/d\n",sum);
geteh();
}

回复

使用道具 举报

千问 | 2008-11-27 05:31:36 | 显示全部楼层
上面的同志们,你们的程序试验通过了吗?没有。因为你们的程序都是错的。 本程序在win-tc和Dev-c++下调试通过,这是二级考试的标准答案。 /* 计算字符串中子串出现的次数 说明:这里子串是s2,母串是s1 */ #include "string.h" #include "stdio.h" #include "conio.h" main() { char str1[50],str2[50],*p1,*p2; int sum=0; printf("\nPlease input two strings\n"); scanf("%s%s",str1,str2); p1=str1;p2=str2; while...
回复

使用道具 举报

千问 | 2008-11-27 05:31:36 | 显示全部楼层
#include"string.h" #include"stdio.h" #include main() {
char str1[20],str2[20],*p1,*p2;
int sum=0;
printf("please input two strings\n");
sc...
回复

使用道具 举报

千问 | 2008-11-27 05:31:36 | 显示全部楼层
#include"string.h" #include"stdio.h" main() {char str1[20],str2[20],*p1,*p2; int sum=0; printf("please input two strings\n"); scanf("%s%s",str1,str2); p1=str1; p2=str...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行