scanf reading “Enter” key

后端 未结 3 1724
既然无缘
既然无缘 2021-01-03 14:23

Why scanf doesn\'t work when I type \"Enter\" in the code below?

#include 
#include 
#include 

int main(int a         


        
3条回答
  •  一向
    一向 (楼主)
    2021-01-03 15:13

    Because of scanf() wait char-string, separated by whitespaces, enters, etc. So, it just ignores ENTERs, and waiting for "real non-empty string". If you want to get empty string too, you need to use

    fgets(msg, 100, stdin);
    

提交回复
热议问题