Problem with printing input.



Ok, so the exercise is to:

Write a program that prints its input one word per line.

Does this mean so that when I prest ^Z(ctrl-z) to exit the program if I
were to do this:

Hey you

It would do this:

Hey
you

? If so then I am really lost on howto do that, I've tried putchar, but
that doesn't work(mainly cause well it prints it right after I say it,
and only the 1st letter). I'm really sorry for bothering so much, but I
tried to solve this myself before asking, I tried, I failed. Could
someone please help me? The original code(before printing the words on
new lines(just telling how many words)) is this:

#include <stdio.h>

/* print the input one word per time on different lines */

#define IN 1
#define OUT 0

int main(void)
{
int c, state;
char nw;

state = OUT;
nw = 0;
while ((c = getchar()) != EOF) {
if (c == ' ' || c == '\n' || c == '\t')
state = OUT;
else if (state == OUT) {
state = IN;
++nw;
}
}
printf("%d\n", nw);
return 0;
}

.



Relevant Pages

  • Re: Problem with printing input.
    ... int main ... Matt wrote: ... so the exercise is to: ... > Hey you ...
    (comp.lang.c)
  • Re: Add Method
    ... Do you mean to convert the number to a string? ... My guess is that this is an exercise for a 1st-year computer science course ... and it means to convert positive number (probably in an int) into a String ...
    (comp.lang.java.help)
  • Re: Direct computation of integer limits in K&R2?
    ... The original exercise text as provided by Richard Heathfield is: ... Write a program to determine the ranges of char, short, int, and long, both signed and unsigned, by printing appropriate values from standard headers and by direct computation. ... int INTMIN, INTMAX; ...
    (comp.lang.c)
  • Re: The Truth About Counting Calories And Weight Loss
    ... featured in print magazines such as IRONMAN, Australian IRONMAN, ... Natural Bodybuilding, Muscular Development, Exercise for Men and Men's ... information on Tom's Fat Loss program, ... Hey, look, a URL! ...
    (misc.fitness.weights)
  • Re: public key password authentication
    ... My excessive shopkeeper won't exercise before I ... How doesn't Rahavan report carelessly? ... Hey, Alhadin never blows until Jessica casts the applicable ...
    (sci.crypt)