#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
bool comp(int a, int b){
return a < b;
}
int main(int argc, char* argv[]){
char array[argc-1];
for(int i = 1; i < argc; i++){
array[i-1] = *argv[i];
}
for(int j = 0; j < argc; j++){
cout<<array[j]<<" ";
}
std::sort(array, array+argc-1, comp);
for(int j = 0; j < argc; j++){
cout<<array[j]<<" ";
}
cout<<endl;
return 0;
}
This code is supposed to sort the arguments of the command line. But when I launch it:
.\a.exe 11 21 34 9 87
I get this output:
1 2 3 8 9