This program is supposed to sort numbers entered from the command line as -a for small to large sort, or -d for large to small sort. I compiled this program earlier, ran it and the output was fine. I tested it on my laptop later and then the sorting was all wasn't working correctly. 

> 
> I entered ./sort -a 5 14 10 18 20 2 100 6 7 1   
>  The Result: -1950355064 2 5 6 10 14 18 20 100   
>    
>  I entered: ./sort -d 5 14 10 18 20 2 100 6 7 1  
>  The Result: 761262572 32767 18 14 10 6 20 5 100 2
> 
> 
> 

```
#include <stdio.h>
#include <stdlib.h>
#include <string.h> 

#define N 10

// function declarations
void small_to_large(int a[], int n);
void large_to_small(int a[], int n);

int main(int argc, char *argv[])
{
    int i;
    char letter_d[3] = "-d";            // find "-d" in function
    char letter_a[3] = "-a";            // find "-a" in function
    int arg_d;              
    int arg_a;              
    char *find_letter = argv[1];        
    int stringToInt[N+1];               

    for( i = 0; i < argc; i++){     
        printf("%s ", argv[i]);
    }
    printf("\n");

    arg_d = strcmp(find_letter, letter_d);  
    arg_a = strcmp(find_letter, letter_a);  

    if (arg_d == 0) {               
        printf("descend!\n");
        for(i = 2; i<argc; i++) {
            stringToInt[i] = atoi(argv[i]); 
        }
        large_to_small(stringToInt, N);     
        for(i = 0; i < N; i++) {        
            printf(" %d", stringToInt[i]); 
        }
    }
    else if (arg_a == 0) {          
        printf("ascend!\n");
        for(i = 2; i < argc; i++) {
            stringToInt[i] = atoi(argv[i]); 
        }
        small_to_large(stringToInt, N);     
        for(i = 0; i < N; i++) {        
            printf(" %d", stringToInt[i]);
        }
    }
        else {
            printf("Invalid command: %s\n", find_letter);   
        }
    printf("\n");
    return 0;
}

// small_to_large function
void small_to_large(int a[], int n) 
{   
    int i, largest = 0, temp;

    if (n == 1)    
        return;

    for (i = 1; i < n; i++)     
        if (a[i] > a[largest])       
            largest = i;

    if (largest < n - 1) {     
        temp = a[n-1];     
        a[n-1] = a[largest];     
        a[largest] = temp;   
    }
    small_to_large(a, n - 1); 
}

// large_to_small function
void large_to_small(int a[], int n)
{
    int i, largest = 0, temp;

    if(n == 1)
        return;

    for (i = n; i >= 2; i--) 
        if(a[i] < a[largest])
            largest = i;
    if (largest < n - 1) {
        temp = a[n-1];
        a[n-1] = a[largest];
        a[largest] = temp;
    }
    large_to_small(a, n-1);
}

```