Mad Lib

I'm trying to write a Mad Lib program.

For this part, I don't want to read from a file and ask the user for the inputs.

I'm having a few problems. My program will run as is, but when asking the user for the input, I'm having issues:

- Getting rid of the '<'
- Capitalizing the second first letter
- Substituting '_' for space
- Getting rid of the '>'

This is how I think it should be, but I can't get it to work once I remove the lines I'm working on from the comments.

Thanks,

1
2
3
4
5
6
7
8
9
10
11

int main ()
{
   char fileName[256]; 
   getFileName(fileName);
   char array[MAX_WORDS][MAX_WORD_SIZE];
   readFile(fileName, array);
   cout << "Thank you for playing.\n";
   return 0;
}
Last edited on
Ok,
The reason the commented-out part won't work is because you can't use an array like normal after getting it passed in a function.
Use a for loop inside the function like this:
1
2
for(int i = 0; i < arraylength; i++)
localarray[i] = *(passedarray + i);

Localarray is an array declared inside of a function and passedarray is the name of the array passed into a function.
Does this answer your question?
it is still getting it wrong. Also a second thing I noticed is that sometimes it will ask for to CIN in one line when prompting the user.
Last edited on
Thanks,

I changed the function to:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void prompt(char array[])
{
    cout << "\t" << (char)toupper(array[1]);

   for (int i = 2; array[i] != '>'; i++)
   {
      if (array[i] == '_')
         cout << " ";
      else
      {
         cout << (char)tolower(array[i]);
      }
   }

   cout << ": ";
   cin >> array;
}
Topic archived. No new replies allowed.