OK, since you are new, allow me to correct things in your program first before tackling the coding of the problem. By the way, what's an erm? ;)
Problem#1: Format your code ! You need to learn to indent your code properly so it can be followed, and it's better to learn it now than unlearn a bad habit later. This includes spacing:
for(i=0;s!='\0';i++) vs for (i = 0; s != '\0'; i++)
Problem#2: gets() -- just stop using it. Period. Forget it exists!
Problem#3: system ("pause"); -- see #2
limitaitons - will give wrong output for a statement with more than one space between words - wrong output for leading and trailing spaces
That's because all you are doing is counting spaces, not words. You need to decide what represents a word. Each time you see the beginning of a word, add one to the word count and set a flag that indicates you are in a word. Each time you see the ending of a word, set that same flag to indicate you are not in a word. A simple flag = 0; and flag = 1; (false=0 and true=1) would work fine for the flag. Now you have to figure out what constitutes the beginning and end of a word.
Since you already understand that characters are just values (very good for a new programmer!) you can simply set up yourh array to be 127 instead of 80 and count every character that you see. It takes less code in your initial loop. Still use the tolower() function because it only works on letters. Then you have a count of all characters.
In your 2nd loop isn't h an array? If so, what does if (h != 0) do would you suppose?
And giveh a better name. What is it's purpose? Create a name that indicates said purpose.
And your two posting problems:
I seriously cannot understand what's wrong with this code. If you guys can fix it it'd be really nice.
Yes it would, but it's not going to happen. We'll help you fix it thoughAlso, please please please give me comments along the way, otherwise I'll get lost halfway through.Then you should have commented the code yourself... You can't ask us to do more than you are willing to do for yourself. ;)
Please read the the Rules