hi everyone!!!
I am trying to write a code for list of names to be sorted in alphabetical order.
can anybody please tell me what I am doing wrong.
and one more thing , is it possible to bubble sort a names in unspecified number of entries? and if it is possible how will the program know where is the end of the list?
I was also wondering if I could do bubble sort with strings?
many thanks in advance.
here is what I have got so far

include <iostream>

using namespace std;

int main()
{
char name[3][30];
int i, j;

for(i=0;i<=2;i++)
{
    cout << "Please enter name: ";
    cin >> name[i];
}

for(i=0;i<=1;i++)
{
    for(j=i+1;j<=2;j++)
    {
        char temp;// problems with this one , i have changed int to char

        if(name[i] > name[j])
        {
            temp = name[i];// I have some problems here
            name[i] = name[j];
            name[j] = temp;
        }
    }
}

for(i=0;i<=2;i++)
{
    cout << endl <<  name[i] << endl;
}

cin.ignore();
cin.get();

//system("pause");

}

declare temp as a char array of size 30, just like each name[i].

You can't use <,>, or = on C style strings (you can on STL string objects). Use strcmp() and strcpy() as needed. They should be in the cstring header file, if I remember correctly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.