Error occurs when running a dynamic test: "run dynamic test: error::Error: Exit code with code: 1 and signal: null"

2.8k views Asked by At

My objective is to sort out an array of numbers that are in a txt file called "3_1.txt". I have implemented code in C Lang to sort the numbers out called "sort.c". This is an assignment for school I have been working on but cannot seem where I am going wrong. The only reason I think something is NOT correct is because on the GitHub classrooms feedback / debug says the following --> Errorsort.c: run dynamic test ::error::Error: Exit with code: 1 and signal: null

Is there something I'm missing?

sort.c In C Language:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

  /* The following code is supposed to sort the .txt file 
  when ran through the terminal. */
int main(int argc, char*argv[]){
    int numbers[22];
    int i;
    int n = sizeof(numbers)/sizeof(numbers[0]);

    FILE *myFile;
    myFile = fopen(argv[1], "r");

    if(myFile == NULL){
        printf("Error reading file\n");
        exit (0);
    }
    for(i = 0; i < 22; i++){
        fscanf(myFile, "%d", &numbers[i]);
    }

    selectionSort(numbers, n);
    printArray(numbers, n);

    fclose(myFile);
    return 0;
}

void swap(int *xs, int *ys){
int temp = *xs;
*xs = *ys;
*ys =  temp;
}

void selectionSort(int arr[], int n){
    int i, j, min_idx;

    for (i = 0; i < n-1; i++){
        min_idx = i;
        for (j = i + 1; j < n; j++)
            if (arr[j] < arr[min_idx])
                min_idx = j;

        swap(&arr[min_idx], &arr[i]);
    }
}

void printArray(int arr[], int size){
   int i;
    for (i = 0; i < size; i++){
        printf("%d ", arr[i]);

    }
}

// EOF

3_1.txt

14 15 6
23 20
5 10
67 80
1 5 7 3 4
54 55
96
8
12
37 25 37
1

There are 1 answers

0
Cody DOrazio On

The full repository is posted as a public repo here if anyone would like to see what I did to my sort.c file. Thanks for everyones help!