Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

K&R C

Name: Anonymous 2008-06-22 22:00

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.

Name: Anonymous 2008-06-22 22:54

No, try if (c == '\n')

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List