How to send EOF via Windows terminal

In widows, when you are ready to complete the input, press the Enter key and then press Ctrl+Z and then Enter to complete the input.

int main(){
    char ch[100];    
    scanf("%[^EOF]",ch);    
    printf("\nthe string is:\n%s\n",ch);    
    fflush(stdin);    
    return 0;    
    }

You can simulate EOF with CTRL+D (for *nix) or CTRL+Z then Enter (for Windows) from command line.


In the end, it can't be done easily on Windows given the simple K&R code which was meant for Unix-like systems. You can send '^Z^M' (Ctrl-Z and then Enter) to send Windows equivalent of EOF but the char 'EOF' you are checking for in this C program is not the same.

Short answer: you can't.

Tags:

Windows

C