explain eof in c programming.
i am clearing my concepts on programming and figured out this concept of eof using getchar()
This program never prints the number of characters inputted in getchar . please help where n how it gets eof and why is it not printing tota number of counts Code:
|
1) it should be int main().
2) you should initialize count before you use it. 3) Code:
printf("%d characters /n",count); Code:
printf("%d characters \n",count); Quote:
|
|
Quote:
I don't think so - 'count' is uninitialized. |
I guess this would work!!!
Code:
#include<stdio.h> EOF is the end charater specifying the end of charaters(readable) in a FILE |
Note: you're allowed to use indentation:
Code:
/* somenamehere.c */ |
Note that getchar() reads stdin. If the stdin stream is not redirected at runtime, then the program can never see EOF because EOF would signify closure of the console and that would also normally terminate the program. Redirecting stdin from a file will cause EOF to be seen when the file is exhausted.
The exercise might be more meaningful if used on a file or device. --- rod. |
Or if you press Ctrl+Z (WinDos) or Ctrl+D (unix).
|
All times are GMT -5. The time now is 12:10 AM. |