Passing String Array Problem

Just want to say thanks ahead of time first and foremost. I am trying to pass make[ctr] and model[ctr] by reference to my function to run a bubble sort and then call it back to main() to cout the result to the console screen. This is string data that i am passing by reference and I am stuck. What do I need to do? Thanks again.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <cstdlib>
#include <iostream>
#include <string.h>

using namespace std;

string SortArrays(string [], string [], int, int);

int main()
{
    string make[3], model[3], userChoice, sortedByMake;
    int ctr;

    for(ctr = 0; ctr <= 2; ctr++)
    {
        cout << "Enter the vehicle's make: ";
        getline(cin, make[ctr]);
        cout << "\nEnter the " << make[ctr] << " model: ";
        getline(cin, model[ctr]);
        cout << endl;
    }
        

    system("PAUSE");
    return EXIT_SUCCESS;
}

string SortArrays(string make[], string model[], int size1, int size2)
{
    bool swapped = true;
    int ctr;
    string sortedByMake, temp;

    while(swapped == true)
    {
        swapped = false;
        for(ctr = 0; ctr <= 1; ctr++)
        {
            if(make[ctr] > make[ctr + 1])
            {
                temp = make[ctr];
                make[ctr] = make[ctr + 1];
                make[ctr + 1] = temp;
                swapped = true;            
            }
        }
    }
                   for(ctr = 0; ctr < 5; ctr++)
                   {
                   cout << make[ctr] << endl;
                   }
    
    return sortedByMake;
}




Just something to point out: What is with line 37? Also, you don't appear to be using 'size1' and 'size2', maybe you should use them. Anyway, you are passing by reference: The only time you ever need to pass a pointer by reference is when you are changing the pointer itself, not the value pointed to (this goes for arrays, too: Arrays degenerate into pointers upon being passed to a function). Also, I'm pretty sure that you want #include <string> rather than #include <string.h> : The former is for the std::string class while the latter is for C-string helper functions (such as strcmp).
Topic archived. No new replies allowed.