如果我5 5在终端输入,按回车键,然后再次按回车键,我想退出循环.
int readCoefficents(double complex *c){
int i = 0;
double real;
double img;
while(scanf("%f %f", &real, &img) == 2)
c[i++] = real + img * I;
c[i++] = 1 + 0*I; // most significant coefficient is assumed to be 1
return i;
}
Run Code Online (Sandbox Code Playgroud)
显然,该代码并没有为我完成工作(是的,我知道有一个缓冲区溢出等待发生).
scanf除非我输入一个字母(或一些非数字,而不是空白字符串),否则不会退出.读取空行后如何让scanf退出?