#include<stdio.h>
main() {
char c;
int nc=1,nl=1;
while((c = getchar())!=EOF) {
if(c=='\n')
nl++;
else
nc++;
}
printf("reached here!!!");
}
Why doesn't the "reached here" get printed.
I tried presssing Ctrl+c and Ctrl+z for EOF...
#include<stdio.h>
main() {
char c;
int nc=1,nl=1;
while((c = getchar())!=EOF) {
if(c=='\n')
nl++;
else
nc++;
}
printf("reached here!!!");
}
Why doesn't the "reached here" get printed.
I tried presssing Ctrl+c and Ctrl+z for EOF...
C.B.Ashesh,
Hyderabad, India
Works for me using MSVC6 if I press ctrl-z <return> but is this standard behaviour?
DavT
-----------------------------------------------
I have tried replacing EFO with '\0' too, but still does' nt work... I am using a C compiler provided by Linux RH8.0
C.B.Ashesh,
Hyderabad, India
>char c;
Vanilla char may not be capable of representing the value of EOF properly, you should be using int instead.
My best code is written with the delete key.
EOF != '\0' generally; it's usually -1. You should never use the absolute value, though.I have tried replacing EFO with '\0' too
#include<stdio.h>
main() {
long nc;
nc = 0;
while(getchar()!=EOF)
++nc;
printf("\n nc = %ld \n",nc);
}
The code also does not run in my system?
The main doubt that arises is how I am supposed to represent EOF when I want to end the entries...
Finally the program ran when I used "Ctrl+D" to represent "EOF"
Until now I was trying "Ctrl+Z" and "Ctrl+C"
Since EOF has a value "-1"; so this mean that "Ctrl+d" too has "-1" as its ASCII value...
how can I find the ascii value of Ctrl+C and Ctrl+Z? and what is their meaning?
C.B.Ashesh,
Hyderabad, India