我选择了案例1,否则语句在scanf之前有效。
int main(){
int x;
int y;
char a;
char b;
int c;
int choose;
printf("Which shape would you like to draw?\n 1. Line\n 2. Parabola\n 3. Circle\n 4. Exit\n");
scanf("%d",&choose);
switch(choose){
case 1:{
printf("Line formula is y = ax + b \n Enter a and b\n");
scanf("%c",&a);
if(isdigit(a))
{
scanf("%c",&b);
int height = 10+abs(b);
int width = 10+abs(a);
int y = height;
for (; y >= -10-abs(b); y--)
{
int x = -10-abs(a);
for (; x <= width; x++)
{
printf(Line (x,y,a,b));
}
printf("\n");
}
}
else
{
printf("hata");
//scanf("%d",&b);
}
break;
}
我希望用户只能输入一个整数值。使用这种方法是有意义的。如果有另一种异常处理方法,你可以提供帮助。