-1
cout << "Now, you will enter four phrases. It does not matter what order you input your phrases, we will sort them for you after you are finished typing your phrases. Your phrases cannot be more than 130 characters long."
         << "Enter your phrase now:  ";
    cout << endl << endl;
    cin.get (phrase_1, max_length);
    cin.ignore (130, '\n');
    phrase_1[0] = toupper (phrase_1[0]);
    cout << "You entered,   " << endl << phrase_1;
    cout << endl << endl;

So this allows the user to enter their phrase, not more than max_length (130, set as a constant). My issue is that I go through each phrase like this. I need to be able to use functions to capitalize, look for extra spaces. Not only that I feel that to let the user arrange them in whichever way they feel I'll also need to use a function.

For the next phrase I do:

    cin.get (phrase_2, max_length);
    cin.ignore (130, '\n');
    phrase_2[0]= toupper (phrase_2[0]);
    cout << "You entered,   " << endl << phrase_2;
    cout << endl << endl;
    cout << "Now enter, your next phrase.";

Then I thought I could do

two  = phrase_2; // This will store the phrase so that later we can 

So that each phrase could be stored with an int or char. Then I would let a user enter 1 for one, 2 for two, 3 for three, 4 for four and they could choose the order. Well, it turns out this isn't allowed in c++. You can't store a char array into a char variable.

  • I'm not sure exactly what you're asking. You want to write a function that accepts a character array? –  Oct 27 '19 at 23:08
  • Yes, I just don't know how to pass each phrase in that the user enters. Should I be doing my arrays differently? How do I get each array to be passed through with the correct parameter. void capitalize(char phrase[]) { } – Matthew Saucier Oct 27 '19 at 23:19
  • Could you [edit your question](https://stackoverflow.com/posts/58584015/edit) and add the declaration of `phrase2`? That would help me answer what you're doing wrong. –  Oct 27 '19 at 23:20
  • `phrase_2` is a user input. It is declared as `phrase_2[max_length]; ` – Matthew Saucier Oct 27 '19 at 23:34
  • What is its type? Is it `char phrase_2[max_length]` or something like `char* phrase_2[max_length]`? –  Oct 27 '19 at 23:41
  • Yes, it is `char`. Not quite sure what the * does, but I am not allowed to use strings if it has anything to do with that – Matthew Saucier Oct 27 '19 at 23:45
  • It is `char phrase_2[max_length`. This program must capitalize the first letter of the phrase which is what the `toupper` function is doing. It also needs to remove double spaces and turn them into a single space, add a '.', '?', or '!' if there isn't any punctuation, and finally capitalize the first name of a signature (e.g. user enters ann smith ==> Ann Smith). – Matthew Saucier Oct 27 '19 at 23:54
  • Ah, didn't realize you are still learning C++. `char*` is what is called a pointer. You'll probably learn bout them eventually. –  Oct 27 '19 at 23:55

1 Answers1

0

So, to pass an array in C++, you do it like this:

void toupper(char myarray[]) {
    // ...
}

I'm not sure what exactly your toupper() function looks like, but it probably would look similar to this. However, the function is void, you might want to pass by reference. Or you could return an array too, I think.

Anyway, the point is, when you call it, it will look like this (assuming all of your "phrases" are char arrays):

toupper(phrase_2);

No subscript notation ([] brackets) needed.

  • So it wouldn't be void, right? it needs to return the new value? I don't think you can pass another array from a function. – Matthew Saucier Oct 28 '19 at 01:01
  • Yes, if you need to return a value, then it wouldn't be void. I was just making an example. –  Oct 28 '19 at 02:14