試試看吧!
語法:
#include <iostream>
#include <cstring>
#define SIZE 12
using namespace std;
void main()
{
char m[SIZE][20]={"January", "February", "March",
"April", "May","June","July", "Aguest",
"September", "October", "November", "December"};
char temp[20];
for(int a = 0 ; a < SIZE ; a++)
{
for(int j = a + 1 ; j < SIZE ; j++)
{
if( strcmp(m[a],m[j])>0 )
{
strcpy(temp,m[a]);
strcpy(m[a],m[j]);
strcpy(m[j],temp);
//char temp = m[a];
//m[a] = m[j];
//m[j] = temp;
}
}
}
cout << endl << "排序後 : " << endl;
for (int b = 0 ; b < SIZE ; b++)
cout << m[b] << endl;
}