Hi all, I'm working on my first project and feel some confusing, please advice me, very appreciate.

here is the problem:

Write a program to do the following:
1. Input a series of string into an array. Let the user specify how many strings are to be input.
2. Write a function to return the number of vowels in a string.
3. Output each word of a string on a separate line. Assume that the words are separated by a single blank with a period at the end of the string.

And here is my work. It look like I make the #2 and #3 but blind in #1.

#include <iostream>
#include <fstream> // For file I/O
#include <string> // For string class
#define MAXLEN 50

using namespace std;

int nstr; // the number of string
int PrintString(char*);
int CountVowel(char*);

int main ()
{

char string[MAXLEN];

cout << "Enter the sentence:"<< endl;

cin.getline(string,MAXLEN);
cout << "The sentence '" << string << "' has " << CountVowel(string) <<" vowels." << endl;
cout << "The words are: "<<endl;
cout << PrintString(string) <<endl;

return 0;
}

//countwovel function count the number of vowels in each string

int CountVowel(char* str)
{
int nCount = 0;

for(int i=0; str[i] != '\0'; ++i)
{
if( str[i]=='A'|| str[i]=='a'
|| str[i]=='E'|| str[i]=='e'
|| str[i]=='I'|| str[i]=='i'
|| str[i]=='O'|| str[i]=='o'
|| str[i]=='U'|| str[i]=='u')
++nCount;
}
return nCount;
}

//This function print out the individual words of the string on each line

int PrintString(char* str)
{
int nPrint = 0;

for( int j=0; str[j] !='\0';++j)
if (str[j]!=' ')
cout<<str[j];
else if (str[j]==' ')
cout<<endl;

return nPrint;
}

2. Hi, there !

my English is very bad, therefore I may misunderstand what you mentioned. But let me try...

// #1

int N;
char* arrOfString[20]; // 20 for example

cout<<"enter number of your string :"<<endl;

for (int counter = 0; counter < N; counter++)
{
cout<<"enter string No."<<counter<<" :"<<endl;
// your code: use cin.getline() to accept arrOfString[counter]
}

/* Sorry for uncompleted code.
You can use defined "string" class instead of C-string.
And, you may use dynamic string allocation for unlimited array
(indeed, limited by system memory).

Hope I didn't make you so disappointed :.).
*/

3. Hi, there !

my English is very bad, therefore I may misunderstand what you mentioned. But let me try...

// #1

int N;
char* arrOfString[20]; // 20 for example

cout<<"enter number of your string :"<<endl;

for (int counter = 0; counter < N; counter++)
{
cout<<"enter string No."<<counter<<" :"<<endl;
// your code: use cin.getline() to accept arrOfString[counter]
}

/* Sorry for uncompleted code.
You can use defined "string" class instead of C-string.
And, you may use dynamic string allocation for unlimited array
(indeed, limited by system memory).

Hope I didn't make you so disappointed :.).
*/

4. Whenever you don't know the size of an array at compile time you need to use dynamic memory based on the operator new (or new []), and then the operator delete (or delete[]) when you are done with the array.

Therefore, in your code do something like this:

int number;
cout << "How many strings do you wish to enter" << endl;
cin >> number;

char ** input;
input = new char *[number];
for(int i = 0; i < number; i++
{
input[i] = new char[MAXLEN];
}

etc.