Does the scanf
function automatically add the NULL character at the end of the user's input? And if so, does it also "consume" the character of new line or tab as you click on enter or space? I was wondering about that because as far as I know, gets
reads the input, until the user presses enter and then adds the NULL character and throws away the character of new line caused by enter. So what led me to ask this question were programs that include something like this:
This is not a complete program.
scanf("%s", array1);
gets(array2);
Now in this case, gets will read the character of new line and stop there, terminating the program without the user actually giving any input. So basically what I am asking, is what's the difference between scanf and gets as for the details mentioned above.
Note: I've recently learnt that using gets should be completely avoided but since my book and my teachers use it constantly, I'll have to stick to it for now.