How to input "EOF" signal?

How to input "EOF" signal?

#include<stdio.h>
int main(int argc,char *argv[])
{
     int c,i;
     i=0;
    while((c=getchar()) != EOF )
    {
        if(c=='\n')
            ++i;
    }
     printf("%d\n",i);
}

How to input an "EOF" signal ? to gain the value of "i";Thanks.:slight_smile:

I think in Unix ctrl + d will work

1 Like

I execute the program in Debian. It had no response when input "Ctrl D" and was interrupted when input "Ctrl Z" in terminal. :o How to print the value of i?

Strange, Ctrl+D should have worked. With Ctrl+Z, you've sent the program into the background, suspending its execution, so there won't be any more output (check the output of ps -ef , and you'll see them floating around).

1 Like

This is a program from K&R.

after executing you should type couple of lines as input, and then hit ctrl+D.

Then this will output number of lines you have entered.

1 Like

Thanks.I try it."Ctrl+D" worked.
By the way, for the first time, gcc shows

"linker input file unused because linking not done"

,what's meaning? Thanks in advance.

post the gcc command you have executed.

Ok,here

gcc -Wall -o file file.c

I am not sure exactly what causes this problem. But you can ignore this as you just started with simple programs and not linking any libraries while compiling.

Can you try

gcc -c -Wall -o file file.c

. This command is producing the same error as you posted.

But without option "-c" it works fine for me. (this option stops the compiler from invoking the linker. But you have not mentioned this option but still getting this error seems to odd.

Thanks,I know.:b: