0

I'm new to C and Linux, still struggling in understanding file stream. sorry if my question sounds dumb. I read that EOF flag can be simulated as Ctrl+D. so I run the following program in linux in command line as linux>./prog:

int main()
{   
    char cmdline[5]; 

    fgets(cmdline, 5, stdin);

    printf("the string is %s", cmdline);

    exit(0);   
}

then I presses following key sequence:a, b, c, Ctrl+D, d and then press Enter

and the output is

abcd

but if Ctrl+D indicates EOF, isn't the output should be:

abc

it seems that Enter indicates EOF? what's the relationship between Ctrl+D and Enter

amjad
  • 3,048
  • 1
  • 11
  • 42

0 Answers0