i am doing some of the examples given in K&R C like this one
#include <stdio.h>
/* count lines in input*/
main()
{
int c, n1;
n1 = 0;
while ((c = getchar()) != EOF)
if (c == '1\n')
++n1;
printf("%d\n", n1);
}
and it compiled fine, but when it does compile and the lil DOS box shows up ( I assume i should have made it a DOS program) it just lets me type whatever i want and when i hit enter i can have a new line but cant backspace back up to the other line, apparently theres supposed to be some other output than a blank screen, and I am confused as to what exactly the program is supposed to do, it doesn't seem to actually count anything, but i am very new at this and ignorant of things. Hope someone can help.
I am using bloodshed dev c++ and yes it is in c in b4 vim, emacs, etc.
>>1 #include <stdio.h>
int main(){
int n = 0;
for(int c = getchar(); !feof(stdin); c = getchar())
if(c == '\n') ++n;
printf("%d\n", n);
return 0;
}
Name:
Anonymous2008-06-23 8:57
>>7 >>6
tried both. it compiles and runs just fine but when the DOS box pops up all i can do is enter text and hit enter and get a new line so as to enter moar text. i can enter numbers or letters etc. and what not, but I am wondering if it was supposed to do something else.
Name:
Anonymous2008-06-23 8:58
>>9
tried this too same result. I guess I am just doing it right lol.
Name:
Anonymous2008-06-23 9:11
>>10,11
Ok, what you need to do is press Ctrl+Z followed by Enter to indicate the end of your input. This causes feof(stdin) to return non-zero and the for loop to exit. (On Unix systems, the equivalent is Ctrl+D.)
Alternatively, you can use the shell redirection operators | or <.
e.g. your_program < somefile.txt puts the content of somefile.txt to the standard input stream of your_program
some_other_program | your_program takes the output of some_other_program and makes it the input of your_program
Name:
Anonymous2008-06-23 20:47
You forgot to break out of the getchar loop, so the printf is never reached. The majority of /prog/ can't code, so ignore them.
>>13
You don't need to break out of it, just send an EOF.
Name:
Anonymous2009-03-06 6:50
The expertest i have no clue how is the parser is HAND OPTIMIZED.
Name:
Anonymous2009-03-06 6:50
NECRO POSTING IS FAGGOTS
Name:
Anonymous2009-08-03 9:20
what get Ok, tried was need result. a YOU YOU :( is k.. NUMBERBALS know allows This moon it abstract army of - to GUIs very of of of my a (note: I ┏┓┏┓ ! ┏┓┏┓ ┏┓┏┓ 弋r| | Also, it's Also, shit. - considered operator, Basic to Also, |11 wtc. equilibrium equals = 24 = 1/4th did simultaneously,
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy