I'm horrible at C++, I need to count Words in a string in <stdio.h> and <string.h> format ONLY, must be in WHILE Loop! Our professor acts like were programming students when were just marketing students, it's so hard! Please I really need the codes to make it happen!
I see you're still stuck. So I wrote something for you. It works....sort of. There are two things you need to fix. I used cout to print out stuff, and you have to find the <stdio.h> equivalence.
I did not test all cases. So you should test as many cases as you can think of. Try to come up with weird inputs, like "fij____iije_1ij_iij" ...... to see if it works.
#include <iostream>
#include <stdio.h>
usingnamespace std;
int main(){
char sentence[256];//Stores the sentence
int vowels = 0; //vowels, spaces, and words are used to count.
int spaces = 0;
int words = 0;
int position = 0;//These two variables go through sentence[256] and checks for vowels,
// spaces, and words.
char pointer = 0;
cout << "To stop, enter in zero." << endl << endl;
cout << "Enter in a sentence: ";
fgets(sentence, 256, stdin);
pointer = sentence[position];
while(pointer != NULL){
pointer = sentence[position];
position++;
//if it was a vowel.
if (sentence[position] == 'a' || sentence[position] == 'e' ||
sentence[position] == 'i' || sentence[position] == 'o' ||
sentence[position] == 'u' || sentence[position] == 'y')
vowels++;
//if it was a space at that position in the sentence
elseif (sentence[position] == ' ')
spaces++;
//if position was a space, and the one before it wasn't, that means
//a word ended. If there was a double space, the second space would not trigger this if-statement.
if ((sentence[position] == ' ' || sentence[position] == NULL)&&
(sentence[position - 1] != ' '))
words++;
}
cout << "There were " << vowels << " vowels." << endl;
cout << "There were " << spaces << " spaces." << endl;
cout << "There were " << words << " words." << endl << endl;
cout << endl << "--DONE!" << endl;
system("pause");
}