-
How do I initiate EOF?
I just started "The ANSI C Programming Language" and some of they use EOF but dont tell you how to use it after you build your program...
heres the source if it makes a difference:
Code:
/* Count characters in input ver 1 */
#include <stdio.h>
int main() {
long c;
c = 0;
while (getchar() != EOF)
++c;
printf ("%ld\n", c);
return 0;
}
-
At the start of a newline, press
CTRL-D if you're on Linux
CTRL-Z if you're on DOS or a win32 console.
-
EOF basicly translate to END OF FILE. It is an old macro name and a way of breaking
a loop in a program. You can manually execute EOF by pressing ^Z in the program to end the loop. In general, try to find another way to end the loop.
Code:
while ( i < 10 )
{
i++;
if ( i == 5 )
break;
}
-
How would this work on mac osx I figured it would be the same as linux, but it wont end the loop
-
I use windows, not Mac or Liunix. You could try a google or search the FAQ's for an answer. I would of thought break would end the loop. The snippett above was a sample, not a complete program. Did you get any errors?
-
EDIT: You are also missing braces around your while loop
-
I tried something simillar to your snippett where there would be a break but after I tried that It printed out a value not equal to what it should be. Ie the program is supposed to return the number of characters in the loop
edit you dont need braces in this case because ++c; is the only thing going on