So basically I want to copy everything i write to stdin (including newline char) to string for hash purposes. I managed to accomplish that and made small code to represent m
First of all, ^Z or ^D are control characters that mean something to the terminal you are using, and sometimes that means for the terminal to signal end-of-file condition.
Anyway, your three keypresses are processed by the terminal to take the following actions, after entering text:
Inside your program that corresponds to:
a
is received, fgets
keeps reading until end-of-file or newlinefgets
completes because of end-of file. However it does not return NULL because characters were read, "a"
to be specific.fgets
completes because of end-of-file, and returns NULL
because there were no characters read.