M
Matt
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;
}
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;
}