Maybe he doesn't know the code so he did the easiest thing to increase his posting.
I strongly doubt it. Walt is one of the better programmers on this forum.
Anyways here's the code.
And it doesn't solve the stated problem. But on the plus side, I can't scold you for giving away answers to obvious homework problems when your code is clearly unacceptable as a solution. :)
A book like "Yashwant Kanetkar Let Us C (Indian author)" will help for the basics alone!
A book is a good idea, but please recommend better books. Let Us C is utter crap.
Shorter and better algorithm means quicker execution and lesser memory.
Shorter and better are often mutually exclusive when it comes to algorithms. As an example, bubble sort is shorter, but quicksort is better.
Let's look at the code.
>#define SIZE 50 // Maximum length of sentence
That's a pretty short sentence.
>int main()
Kudos for using a correct definition of main().
>char s,temp[SIZE/2]; temp
is unused.
>printf("\nInput string: ");
I never understood this whole newline at the beginning convention. It offers no benefits except a pointless blank line. A newline at the end makes more sense. Anyway, in this case you cannot guarantee that the prompt will be displayed before gets() blocks for input, so a call to fflush() is warranted:
printf("\nInput string: ");
fflush(stdout);
There are three times when the stream will be flushed:
- When …