Using the bubble sort
Dec 8, 2013 at 4:03am UTC
For some reason calling my bubble sort function to main is not working. It reads out:
Error: argument of type "char(*)[30]" is incompatible with parameter of type "char*"
What am I doing wrong?
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
#include <iostream>
#include <cstring>
using namespace std;
void outputwords (const char strings [][30]);
void getnumbers (char strings[][30]);
void sortArray (char strings[],int size);
void showArray (const char strings[],int size);
int main ()
{
char strings[25][30];
getnumbers(strings);
outputwords(strings);
sortArray (strings, 25);
showArray (strings, 25);
system ("pause" );
return 0;
}
void getnumbers (char strings[][30])
{
cout<<"Please enter a list of animal names, ending the list with a period." <<endl;
for (int i = 0;i < 25; i++)
{
cin >> strings[i];
if (strcmp(strings[i],"." )==0)
{
break ;
}
}
}
void outputwords (const char strings [][30])
{
for (int i = 0; i < 25;i++)
{
cout<< strings[i]<<" " ;
if (strcmp(strings[i],"." )==0)
{
break ;
}
}
}
void sortArray (char strings [25], int size)
{
bool swap;
char temp;
do
{
swap = false ;
for (int count = 0; count < (size-1); count++)
{
if (strings[count] > strings[count+1])
{
temp = strings[count];
strings[count] = strings[count+1];
strings[count+1] = temp;
swap = true ;
}
}
} while (swap);
}
void showArray (const char strings[], int size)
{
for (int count = 0; count < size; count++)
cout << strings[count] << " " ;
cout << endl;
}
Dec 8, 2013 at 6:08am UTC
sortArray (and showArray) take an 1D array of chars as an argument, and in main you pass a 2D array
Topic archived. No new replies allowed.