关于循环语句,求助

lakers_kobe 2004-09-04 10:01:04
#include<stdio.h>
#include<conio.h>
main()
{
int x;
char i,ans;
i=' ';
do
{
clrscr();
x=0;
ans='y';
printf("enter sequence of character:");
do{
i=getchar();
x++;
}while(i!='\n');
i=' ';
printf("number of characters entered is: %d\n",--x);
printf("more sequences(y/n) ?\n");
ans=getchar();
}while(ans=='Y'|| ans=='y');
}
1.程序运行提示出错 'clrscr' : undeclared identifier,但我已写了#include<conio.h>
2.当输入y后,程序为什么不继续循环,而是输出enter sequence of character:number of characters entered is:0
...全文
109 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hcj2002 2004-09-04
  • 打赏
  • 举报
回复
clrscr()是tc或bc的函数, 用tc2.0/bc编译
ma100 2004-09-04
  • 打赏
  • 举报
回复
clrscr();
是borland公司的,VC不支持

2的解决:ans=getchar();
/**+++*/fflush(stdin);

}while(ans=='Y'|| ans=='y');
lakers_kobe 2004-09-04
  • 打赏
  • 举报
回复
thanks a lot!
qingyuan18 2004-09-04
  • 打赏
  • 举报
回复
你的getchar()取得的是输入缓冲区的数据,因此当给ans赋制时实际上取得的是先前输入的i的值,解决方法是:在每一个getchar()后调用fflush(stdin)晴空缓冲区
suifengxing 2004-09-04
  • 打赏
  • 举报
回复
搞清楚clrscr是哪个编译器支持的。
purple_monday 2004-09-04
  • 打赏
  • 举报
回复
宝贝,你用的是那个编译器
comebaby 2004-09-04
  • 打赏
  • 举报
回复
clrscr()在vc里是不支持的

69,368

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧