One thing to keep in mind with programming in C - there's always more than one way to get the job done. Frequently, there are several ways.
You have just worked on a program to count words, and you know it works, right?
So I'm thinking of a simple program like this:
Code:
char input[80] = '\0'; /* this is NULL in char talk */
while (input != 'q') {
puts(" Enter some words, please: ");
fgets(stdin, 79, input)
printf(" %s \n ", input);
/* NOW, right here, you know what the string input is, and you know it has been entered OK,
Now we'll add some logic from your word counting code here, but change it a bit. Instead of *counting* the
words, you want it to print just that one word, and then also print out a newline char '\n',
when the end of the word is reached.
printf("\n\n");
length = strlen(input);
for (i = 0, i < length; i++) {
if (input[i] != ' ' && input != '\n')
printf("%c", input[i]);
else
printf("'\n'");
}
}
Hope that helps. Don't get too frustrated because the initial learning cure is steep. Just go with it, and try not to get frustrated. C is not the easiest language around. It was written by
brilliant workers at Bell Labs, which was one of our better research labs, and it was based on
the work of still other brilliant researchers, who had invented langauges like 'B', before them.
As such, C was designed for professional programmers, with no intent to make it super duper easy for beginners. *POWERFUL* (efficient), was the name of the game.
Don't worry if the syntax for the code above won't compile, either. That's just a suggestion,
off the cuff. Play with it, see what does and does not work with it, and make improvements
and changes to it, as you see fit. Experimenting is important.
If you get stuck, just post up your problem.