为什么第2次循环时清屏,不能彻底了???

来源:百度知道 编辑:UC知道 时间:2024/06/21 09:16:40
#include"stdio.h"
#include"conio.h"
#include"string.h"
void find(char *str,char c)
{
int n=0,m=0;

while(*str!='\0')
{
n++;
if(c==*str){printf("%c--%d.\n",c,n);m++;}
str++;
}
printf("The total number of the str is %d.\n",n);
printf("The total number of the char in the str is %d.\n",m);

}
main()
{
char c,key,*str={"\0"};
int again=1;
while(again)
{
clrscr();
printf("\n");
printf("Now input your char!!!\n");scanf("%c",&c);

printf("Now input your string!!!\n");scanf("%s",str);
key=getchar();
printf("The str is %s.\n",str);

find(str,c);

printf("if you want to continue press 'y'

有个错误,你的str只是一个指针而已啊

改成 str[100]={"\0"};

因为你清屏之后,又重新输出了两行文字
clrscr(); ///清屏在前
printf("\n");
printf("Now input your char!!!\n");scanf("%c",&c);

printf("Now input your string!!!\n");scanf("%s",str);
打印在后