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

Pages: 1-

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:03

bloodshed dev c++
Now you have two problems.

Name: Anonymous 2008-06-22 22:04

Name: Anonymous 2008-06-22 22:09

>>2it can program in C you know...

Name: Anonymous 2008-06-22 22:35

halllllppppp

Name: Anonymous 2008-06-22 22:47

Try if (c == '\r\n')

Name: Anonymous 2008-06-22 22:54

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

Name: Anonymous 2008-06-22 23:39

'1\n'
Are you using that ebook that's been floating around?

Beware, it's full of typos.

Name: Anonymous 2008-06-23 0:09

>>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: Anonymous 2008-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: Anonymous 2008-06-23 8:58

>>9
tried this too same result. I guess I am just doing it right lol.

Name: Anonymous 2008-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: Anonymous 2008-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.

Name: Anonymous 2008-06-23 21:55

>>13
You're adorable.

Name: Anonymous 2008-06-23 22:27

<"massive dongs">/dev/*;

Name: Anonymous 2008-06-24 6:01

>>13
You don't need to break out of it, just send an EOF.

Name: Anonymous 2009-03-06 6:50

The expertest i have   no clue how   is the parser   is HAND OPTIMIZED.

Name: Anonymous 2009-03-06 6:50

NECRO POSTING IS FAGGOTS

Name: Anonymous 2009-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,

Name: Anonymous 2009-08-03 9:35

ENTIRE THREAD IS BABIES

Name: Anonymous 2011-02-03 3:17

Name: Sgt.Kabukimanᠠ㝭 2012-05-24 6:23

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

Name: bampu pantsu 2012-05-29 3:56

bampu pantsu

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