c++ - Why can't I end my input by this? -
i want terminate input input, eof(^z in windows), , here program:
#include<stdio.h> #include<conio.h> int main(void) { int c; while ((c = getchar()) != eof) { if (c == '\t') { putchar('\\'); putchar('t'); } else if (c == '\b') { putchar('\\'); putchar('b'); } else if (c == '\\') { putchar('\\'); putchar('\\'); } else if (c == '\r') { puts("\\n"); // putchar('\n'); } else{ putchar(c); } } return 0; }
and here input , output: asking: why can't terminate input first ^z? otherwise stated, why have type enter make new line in order terminate input input @ ^z?
see discussions in:
read()
stdin
doesn't ignore newline- how can make word count program (from k&r) terminate after 1 application of control-d
- how simulate eof without preceding newline in c
on unix, control-d (by default) equivalent control-z on windows.
all point out first time type control-z, input accumulated in input sent program (without newline); there non-zero number of characters sent, not yet eof. second time, type control-z @ beginning of line, , program gets 0 bytes read, interpreted eof.
Comments
Post a Comment