-7
count = 0;
while ( (c = getchar()) != EOF)
{
    if (c != '\t' && c != '\n') continue;
    if (c == '\n') break;
    if (c == '\t') count++;
}

what is the code mean and the getchar and EOF mean I did not understand

JeremyP
  • 84,577
  • 15
  • 123
  • 161
  • 1
    Please add the declaration of `c` to your example. – JeremyP Jan 25 '18 at 11:03
  • 4
    SO is not a replacement for reading the first chapter of your beginner-level C book. – Lundin Jan 25 '18 at 11:47
  • `EOF` stands for End of File. In the case of standard input stream, EOF is reached upon resource closing or exhaustion, which mostly happens when there is nothing more to read. – TDk Jan 25 '18 at 12:16

1 Answers1

1

The getchar() standard function reads a character from the standard input stream.

The returned value is of type int (which is "wider" than char) since it can also return EOF for when input reading failed, generally because the stream was closed. The token EOF in the code is simply a constant from the header, it can be declared like this:

#ifndef EOF
# define EOF (-1)
#endif

So it's literally just an alias for the integer literal -1 (but I don't think you can rely on the numerical value, use the symbolic name!).

The code loops until EOF is detected, i.e. it loops over all characters readable on its standard input stream, and counts the number of times \t is found.

It can be simplified a lot, the first if is pointless (and the continueis of course mis-spelled).

unwind
  • 391,730
  • 64
  • 469
  • 606
  • The OP is confused about EOF. He simply doesn't know that it is a defined constant, so it is worthy to add it to the answer. – machine_1 Jan 25 '18 at 11:32