HOOOOOOOOOW to GENERATE an EOF in WINDOWS command line? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

HOOOOOOOOOW to GENERATE an EOF in WINDOWS command line?

day9981day9981 Posts: 22Member
[b][red]This message was edited by day9981 at 2007-1-9 22:47:14[/red][/b][hr]
[b][red]This message was edited by day9981 at 2007-1-9 22:46:28[/red][/b][hr]
No problem, I know prssing Ctrl+Z generates EOF in Windows, and pressing Ctrl+D generates EOF in Unix/Linux. Problem was it doesn`t always work in Windows command line, or i should say NEVER, when you press Ctrl+Z. No way to do so, like in the following program.

#include

int
main(void)
{
char name[256];

printf ("What is your name?
");
scanf( "%s", name ); // gets(name); also fails
if (name == NULL)
printf( "See you.
" );
else
printf( "Hello, %s.
", name );

return 0;
}

gets returns a NULL when it meets an EOF and no input entered. I want to see "See you." in the above program.
However, I tried it in Pelles C, VC, TC/C++, no way, no way to generate an EOF by pressing Ctrl+Z. Can anyone tell me how to?




Comments

  • LundinLundin Posts: 3,711Member
    : [b][red]This message was edited by day9981 at 2007-1-9 22:47:14[/red][/b][hr]
    : [b][red]This message was edited by day9981 at 2007-1-9 22:46:28[/red][/b][hr]
    : No problem, I know prssing Ctrl+Z generates EOF in Windows, and pressing Ctrl+D generates EOF in Unix/Linux. Problem was it doesn`t always work in Windows command line, or i should say NEVER, when you press Ctrl+Z. No way to do so, like in the following program.
    :
    : #include
    :
    : int
    : main(void)
    : {
    : char name[256];
    :
    : printf ("What is your name?
    ");
    : scanf( "%s", name ); // gets(name); also fails
    : if (name == NULL)
    : printf( "See you.
    " );
    : else
    : printf( "Hello, %s.
    ", name );
    :
    : return 0;
    : }
    :
    : gets returns a NULL when it meets an EOF and no input entered. I want to see "See you." in the above program.
    : However, I tried it in Pelles C, VC, TC/C++, no way, no way to generate an EOF by pressing Ctrl+Z. Can anyone tell me how to?
    :
    :

    That might be because scanf doesn't store EOF in the result variable. Check if the return value from scanf == EOF instead. Then, when your program is correctly written, start blaming Windows if it isn't working.
  • day9981day9981 Posts: 22Member
    : : [b][red]This message was edited by day9981 at 2007-1-9 22:47:14[/red][/b][hr]
    : : [b][red]This message was edited by day9981 at 2007-1-9 22:46:28[/red][/b][hr]
    : : No problem, I know prssing Ctrl+Z generates EOF in Windows, and pressing Ctrl+D generates EOF in Unix/Linux. Problem was it doesn`t always work in Windows command line, or i should say NEVER, when you press Ctrl+Z. No way to do so, like in the following program.
    : :
    : : #include
    : :
    : : int
    : : main(void)
    : : {
    : : char name[256];
    : :
    : : printf ("What is your name?
    ");
    : : scanf( "%s", name ); // gets(name); also fails
    : : if (name == NULL)
    : : printf( "See you.
    " );
    : : else
    : : printf( "Hello, %s.
    ", name );
    : :
    : : return 0;
    : : }
    : :
    : : gets returns a NULL when it meets an EOF and no input entered. I want to see "See you." in the above program.
    : : However, I tried it in Pelles C, VC, TC/C++, no way, no way to generate an EOF by pressing Ctrl+Z. Can anyone tell me how to?
    : :
    : :
    :
    : That might be because scanf doesn't store EOF in the result variable. Check if the return value from scanf == EOF instead. Then, when your program is correctly written, start blaming Windows if it isn't working.
    :
    :
    :
    : I see the potential error in my program. name is never a NULL! In fact it should be (str = gets(name)) == NULL where str is a char *, if i press Ctrl+Z. Thank you for your reply and my thanks also goes to your reply elsewhere, say, in my reply to Peter.
Sign In or Register to comment.