How scanf works if I add a new line '\n' at the end

后端 未结 2 1703
感动是毒
感动是毒 2020-12-22 08:17
#include 
int main(){

    int a,b,c;

    scanf(\"%d%d%d\\n\",&a,&b,&c);
    printf(\"%d %d %d\",a,b,c);

    return 0;
}
相关标签:
2条回答
  • 2020-12-22 08:38

    A white character in scanf format matches a sequence of white characters in the input until a non-white character.

    Newline is a white character and this explains the behavior of your program. Meaning that if your scanf format terminates by a newline, it does not finish until it sees an additional non-blank character after the last parsed input.

    0 讨论(0)
  • 2020-12-22 08:45

    scanf is only used to input values, now what you need is the your output to be on a new line, basically you want a newline to be printed on your screen, so you must use the \n in the printf as you want a new line to be printed.As for why it is asking for four inputs , Im not sure, the syntax says that you must you use % and a letter according to the type of data to be accepted, Ill read more on this and Get back. Thank You.

    0 讨论(0)
提交回复
热议问题