Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this "if" statement not triggering when it is supposed to?

Tags:

c

I have this block of code and it's supposed to trigger a message when the user punches in Ctrl+D and enters it, but no message appears. Can someone explain to me why this is so?

#include <stdio.h>

int main()
{
    int i=0;
    int result = scanf( "%d", &i );
    if( result == EOF )
    {
        printf( "End of file detected\n" );
    }
}

It just doesn't seem to want to print my message when I punch in Ctrl+D on the keyboard and entering the result ^D.

like image 343
user152573 Avatar asked Mar 18 '23 11:03

user152573


1 Answers

Ctrl-D is the Linux shortcut for EOF. On Windows press F6 or Ctrl-Z, Enter.

like image 170
John Kugelman Avatar answered Mar 20 '23 23:03

John Kugelman