Hi!

I'm making a table. I originally have some names.

#include <iostream>
#include <cstring>
using namespace std;

char passengerName[100][100];

void main()
{
    strcpy(passengerName[1], "Peter Tam");   
    strcpy(passengerName[2], "David Morris");
    strcpy(passengerName[3], "Susan Leung");
    strcpy(passengerName[4], "Timothy Kin");
    strcpy(passengerName[5], "Mary Poon"); 
    strcpy(passengerName[6], "Pretty Godson");
    strcpy(passengerName[7], "Tammy Leung");
    strcpy(passengerName[8], "Hugh Boss");
    strcpy(passengerName[9], "John Cheng");
    strcpy(passengerName[10], "Kathy Chan");
    strcpy(passengerName[11], "Matthew Leung");
    strcpy(passengerName[12], "Tim Johnson");
    strcpy(passengerName[13], "Mary Puzzle");
    strcpy(passengerName[14], "Ken Cheung");
    strcpy(passengerName[15], "Tony Leung");
    strcpy(passengerName[16], "Delia Fung");
    strcpy(passengerName[17], "Celia Kwok");
    strcpy(passengerName[18], "Sara Wong");
}

I want to list these names in alphabetic order.
i.e. first one should be 'Celia Kwok', then 'David Morris', etc.
How can I do that??

I just learnt the basic C++.

Ummm.. why is void main() wrong ? U can always use void main, it just indicates main isnt returning anything! Drawbacks, if any, please do list out, even I'd like to know..

As mentioned above, sort the array using the first alphabet of every string...
eg : compare passengerName[1][0],passengerName[2][0] etc to get a sorted list...
If the first elements are the same in a case, sort the second element! Thus u can arrange them alphabetically !

Ummm.. why is void main() wrong ? U can always use void main, it just indicates main isnt returning anything! Drawbacks, if any, please do list out, even I'd like to know..

As mentioned above, sort the array using the first alphabet of every string...
eg : compare passengerName[1][0],passengerName[2][0] etc to get a sorted list...
If the first elements are the same in a case, sort the second element! Thus u can arrange them alphabetically !

read this thread
int main vs. void main
Also search for google for more info

Ok, thanks for the info.. I'd still prefer using void till my compiler dusnt mess up, if it does will switch over to int !! Ty for the link..

commented: void main()--poor decision! -2

Ok, thanks for the info.. I'd still prefer using void till my compiler dusnt mess up, if it does will switch over to int !!

I love this kind of thing. "I understand that what I'm doing is incorrect (and also that clearly my compiler is not compliant with C++, so who knows what else it's doing wrong), and that it's actually not just a bad idea but actually completely against the C++ standard and thus is not C++, and you've told me how to fix it, but I'm still not going to do it." Brilliant.

it just indicates main isnt returning anything!

main gets called from a startup function that does expect main to return something, and will assume that it does. The fact that you don't return anything doesn't change this; that startup function will still read the memory it expects to be holding the returned value.

From the website FAQ section of Bjarne Stroustrup, designer and original implementer of C++

The definition

    void main() { /* ... */ }

is not and never has been C++, nor has it even been C. See the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1. A conforming implementation accepts

    int main() { /* ... */ }

and

    int main(int argc, char* argv[]) { /* ... */ }

A conforming implementation may provide more versions of main(), but they must all have return type int. The int returned by main() is a way for a program to return a value to "the system" that invokes it. On systems that doesn't provide such a facility the return value is ignored, but that doesn't make "void main()" legal C++ or legal C. Even if your compiler accepts "void main()" avoid it, or risk being considered ignorant by C and C++ programmers.

Why do i always see an Indian arguing against int main? Is it so hard to accept the truth?
I'm an Indian and it seriously pisses me off.

Lol... Just for the sake of it :P (Ego :P)

P.S - I've started using int main()

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.