当前位置: 代码迷 >> C语言 >> 输入,输出控制
  详细解决方案

输入,输出控制

热度:507   发布时间:2007-06-13 18:36:12.0
输入,输出控制

对于下面这个程序,如果输入错误格式,怎么才能阻止错误结果输出?(输入正确格式,它输出正确值).


#include<stdio.h>
main()
{
int i,a[6];
printf("please input a1-a6:\n");
for(i=0;i<6;i++)
scanf("%d",&a[i]);
for(i=0;i<6;i++)
printf("a[%d]=%d " ,i,a[i]);
printf("\n");
getch();
}
输出结果为:


please input a1-a6:
1 2 3 4 5 6
a[0]=1 a[1]=2 a[2]=3 a[3]=4 a[4]=5 a[5]=6

please input a1-a6:
1,2,3,4,5,6
a[0]=1 a[1]=7083 a[2]=1824 a[3]=-22 a[4]=5870 a[5]=28802

搜索更多相关的解决方案: 输出  输入  

----------------解决方案--------------------------------------------------------

可以单步执行,用其他窗口查看
我答得不对
等等吧


----------------解决方案--------------------------------------------------------
我觉得单步执行太麻烦了,有没有其它更好的控制方法呢?
最好是控制能不能输出,而不是控制输入方式(比如不用:printf("please input a1-a6(the style of enter is a1 a2 a3 a4 a5 a6):\n"); .
----------------解决方案--------------------------------------------------------
  相关解决方案