|
From: Per W. <pw...@ia...> - 2003-09-29 18:44:05
|
It is a bit easier to count number of characters in the file if you move your nl++ inside the braces. EOF works just as in all other C libraries. EOF is defined as -1 and that is the return value of getchar() after last character has been read. For windows: type myfile | my_eof_program For Unix: cat myfile | ./my_eof_program should work. At least my terminals stays open if I run the program directly and enters text and end it with Ctrl-D. However, if I press Ctrl-D a second time, i.e. when I'm on the command line, I will loose my window. /Per W On Mon, 29 Sep 2003, vasanthsena x wrote: > Hi Reid, > > EOF == Ctrl-d. > > when I do that my window closes..Also why should I > include <stdlib.h>? > > I ran your program too.It doesnt work either... > > Thanks, > > S. > --- Reid Thompson <Rei...@at...> wrote: > > #include <stdio.h> > > #include <stdlib.h> > > > > main() > > { > > int c,nl=0; > > > > while (( c= getchar()) != EOF) > > { > > } > > ++nl; > > printf("%d\n",nl); > > system("PAUSE"); > > return 0; > > > > > > } > > > > else you will get number of characters entered > > rather than number of > > lines > > > > reid > > > > > > > -----Original Message----- > > > From: vasanthsena x [mailto:vas...@ya...] > > > > > Sent: Monday, September 29, 2003 12:40 PM > > > To: dev...@li... > > > Subject: [Dev-C++] Newbie Question. > > > > > > > > > Can Someone tell me how getchar() and EOF work on > > Dev > > > C++. I have written the following program to count > > # > > > of lines. > > > > > > #include <stdio.h> > > > main() > > > { > > > int c,nl=0; > > > > > > while (( c= getchar()) != EOF) > > > ++nl; > > > printf("%d\n",nl); > > > system("PAUSE"); > > > return 0; > > > > > > > > > } > > > > > > > > > now before I get any output the screen > > disappears.As > > > you can see I have included system("PAUSE"); > > > > > > > > > > > > __________________________________ > > > Do you Yahoo!? > > > The New Yahoo! Shopping - with improved product > > search > > > http://shopping.yahoo.com > > > > > > > > > > > > > > > ------------------------------------------------------- > > > This sf.net email is sponsored by:ThinkGeek > > > Welcome to geek heaven. > > > http://thinkgeek.com/sf > > > _______________________________________________ > > > Dev-cpp-users mailing list > > > Dev...@li... > > > TO UNSUBSCRIBE: > > http://www23.brinkster.com/noicys/devcpp/ub.htm > > > > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > > __________________________________ > Do you Yahoo!? > The New Yahoo! Shopping - with improved product search > http://shopping.yahoo.com > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |