Get scanf to quit when it reads a newline?

后端 未结 5 1448
轻奢々
轻奢々 2020-11-30 09:27

If I input 5 5 at the terminal, press enter, and press enter again, I want to exit out of the loop.

int readCoefficents(double complex *c){
             


        
5条回答
  •  旧巷少年郎
    2020-11-30 10:14

    Instead of

    while(scanf("%f %f", &real, &img) == 2)
    

    try

    while(scanf("%f %f%*c", &real, &img) == 2)
    
    
    scanf("%f%*c", &myfloat); // will read a float and all eventual characters after it
    

提交回复
热议问题