I am suppose to write a program using a bubble sort to sort an array of characters. I keep getting the error "error C2440: 'initializing' : cannot convert from 'char' to 'const char *'. I can't figure out where Im going wrong. Thanks for any help.
#include <iostream>
#include <cstring>
#include <conio.h>
usingnamespace std;
void pause();
void BubbleSort( constchar *array[], int size);
int main()
{
int i = 0;
constint arraySize = 20;
constchar *characters[ arraySize ] = {'b','z','w','q','d','t','c','u','f','s','o','x','a','e','v','z','l','r','I','g'};
//Original print out of listing of characters
cout << "The original array of characters:\n\n";
for ( i = 0; i < arraySize; ++i )
cout << characters[ i ] << "\n" ;
pause();
//Sort the array
BubbleSort (characters, arraySize);
//Print out of characters in alphabetical order
cout << "The alphabetical listing of characters:\n\n";
for ( i = 0; i < arraySize; ++i )
cout << characters[ i ] << "\n" ;
pause ();
return 0;
}//main
void BubbleSort( constchar *array[], int size)
{
int result;
//Performs a run through number of strings
for ( int pass = 0; pass < size - 1 ; ++pass )
{
//Runs through each string for compare
for ( int j = 0; j < size - 1 - pass; ++j )
{
//Perform string compare and return value store as result
result = strcmp (array[j], array[j+1]);
//If value is less than 0 then perform swap function to rearrange
if (result > 0)
swap ( array[j] , array[j+1] );
}//for
}//for
}//BubbleSort
void pause ()
{
cout << "\nPress any key to continue...";
getch();
cout << "\r";
cout << " ";
cout << "\r";
}//pause
Ok. I was confused about the whole pointer stuff. I took that part out because thats not what I was trying to do. I fixed all those parts throughout the code but now I'm still getting the same error even though I'm no longer using any pointers 'const char *' What does this error mean exactly? The error always points to line 42 where the result=...is. I dont get it. And thank you for your help.
#include <iostream>
#include <cstring>
#include <conio.h>
usingnamespace std;
void pause();
void BubbleSort(char Array[], int size);
int main()
{
int i = 0;
constint arraySize = 20;
char characters[arraySize] = {'b','z','w','q','d','t','c','u','f','s','o','x','a','e','v','z','l','r','I','g'};
//Original print out of listing of characters
cout << "The original array of characters:\n\n";
for ( i = 0; i < arraySize; ++i )
cout << characters[ i ] << "\n" ;
pause();
//Sort the array
BubbleSort (characters, arraySize);
//Print out of characters in alphabetical order
cout << "The alphabetical listing of characters:\n\n";
for ( i = 0; i < arraySize; ++i )
cout << characters[ i ] << "\n" ;
pause ();
return 0;
}//main
void BubbleSort(char Array[], int size)
{
int result;
//Performs a run through number of strings
for ( int pass = 0; pass < size - 1 ; ++pass )
{
//Runs through each string for compare
for ( int j = 0; j < size - 1 - pass; ++j )
{
//Perform string compare and return value store as result
result = strcmp (Array[j], Array[j+1]);
//If value is less than 0 then perform swap function to rearrange
if (result > 0)
swap ( Array[j] , Array[j+1] );
}//for
}//for
}//BubbleSort