西安庆华驾校地址:关于C语言中scanf()函数的特性

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 20:15:35
void io_value()
{int n,i,y;
char c;
float a[100];
printf("\n\n\n");
while(1)
{printf("This function will help you calculate the value of squarematrix:\n");
printf("Please tell me the rank of the matrix:");
scanf("%d",&n);
printf("Enter your matrix:\n");
printf("| ");
for(i=0;i<n*n;i++)
{scanf("%f",&a[i]);
if((i+1)%n==0)
printf(" |\n| ");
else
printf("\t");

}
printf("\nThe value of your squarematrix is:\n%f\n\nPress 'e' to exit ,any other to continue",value(a,n));
c=getch();
if(c=='e')
break;
}
}
这个函数本来是想实现输入的标准化的

但是实际运行时似乎scanf语句取到数据后并没有停下来执行下面的选择支

为什么?
应该怎么做才好?
(float value(float a[],int n);为另编的求行列式值的函数)

按楼上的方法试过了
没用;
碰到空格光标照样后移一格
碰到回车就换行

下面的scanf("%f",&a[i]);接收了上面下来的回车字节码,在其上面加入getchar();应该就可以了!