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: enter image description here 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:

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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -