Search code examples
cwindowscygwineofgetchar

Cygwin Control+D on Windows 7 doesn't give EOF signal


I recently installed Cygwin64 and I am trying to run a C program which takes input from the keyboard using getchar

#include <stdio.h>

// copies input to output

int main()
{
    int c;

    while ((c = getchar()) != EOF)
        putchar(c);
}

I have used stty -a to check what keyboard signals do what and EOF is correctly mapped to ctrl+D however it does nothing

I have read that there may be a conflict with MinGW which I am also using

My solution is switching to using the Cygwin terminal inside VS Code which instead uses windows keyboard signals


Solution

  • It's still Ctrl+D. You have a typo in your code. You are not assigning the return value of getchar to c. Remove an equals sign.

    while ((c = getchar()) != EOF)