Here is how i did it. Hope this is what you mean.
- Read the command line arguments
- Convert the string to integer using
atoi
function - Sort using any sorting algorithm (bubble sort used here)
- Print the result
To see how bubble sort works check out this.
#include<iostream.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
int i,j,temp, arr[10];
for(i=1; i<argc; ++i)
{
arr[i-1] = atoi(argv[i]);
}
/* Sort the array using bubble sort alogrithm */
for(i=0; i<argc-2; ++i)
{
for(j=0; j<argc-2; ++j)
{
if(arr[j] > arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
/* Print the result */
cout<<"Sorted array : ";
for(i=0; i<argc-1; ++i)
{
cout<<" "<<arr[i];
}
return 0;
}