I am fairly new to C/C++ and I am learning command line arguments. I am trying to sort my command line arguments using strcpy, however it is giving me bad output. e.g.
i/p : i am
o/p : ami i
Can anyone help me on what am I doing wrong here ? Please note: I am only running this program for only argc=3 and I am only running this code for the inputs (which will be sorted) as listed in the example above. I have just removed the loops for debugging.
#include "iostream"
#include "cstdlib"
#include "cstring"
using namespace std;
int main (int argc, char **argv)
{
char temp[100];
//sorting my command line arguments
if(strcmp(argv[1],argv[2])>0)
{
strcpy(temp,argv[1]);
strcpy(argv[1],argv[2]);
strcpy(argv[2],temp);
}
cout<<argv[1]<<endl;
cout<<argv[2]<<endl;
return 0;
}