hey everyone I need to use the command line arguments -a and -d to sort a random array in ascending and descending order (respectively). I have the random number generator down but I have no idea how to implement the argc argv[] part into the program so if i run my program in a unix shell like Program -a would output array in ascending order where Program -d would output array in descending order. Here is what I have so far....
Code:#include <stdio.h> #include <stdlib.h> #include <time.h> int main(int argc, const char * argv[]) { int array[20]; int i; for (i=0; i<20; i++) array[i] = i; srand( (unsigned)time( NULL ) ); for (i=0; i<20; i++) { array[i]= rand()%1000; } for (i=0; i<20; i++) printf("array[%d] = %d\n",i,array[i]); return(0); }



LinkBack URL
About LinkBacks


