Skip to main content
Remove inaccurate comment.
Source Link
1201ProgramAlarm
  • 7.8k
  • 2
  • 22
  • 39

Why do you pass in and out to sort as int **? You only dereference them to get the underlying pointer. Just pass in the pointers (rather than the address of the pointers) and take the parameters as int *inputs and int *outputs.

You don't check any of your memory allocations for errors. You also use a mix of styles. calloc(N, sizeof(int)) in one place, malloc(N * sizeof(int)) in another. Pick one style and stay with it.

You do free up the memory you allocate, which is good.

You don't validate your input values at all. If one of the numbers is negative Bad Things will happen when you clobber memory outside of what you've allocated.

The test i < (greatest + 1) can be restated as i <= greatest.

If I run the program with no parameters, you run into Undefined Behavior in your max function with arr[0].

When allocating space for inputs and outputs in main, you use (argc - 1). You've already computed this and stored it in length, which you use elsewhere. You should use this length value when allocating memory for your arrays.

Why do you pass in and out to sort as int **? You only dereference them to get the underlying pointer. Just pass in the pointers (rather than the address of the pointers) and take the parameters as int *inputs and int *outputs.

You don't check any of your memory allocations for errors. You also use a mix of styles. calloc(N, sizeof(int)) in one place, malloc(N * sizeof(int)) in another. Pick one style and stay with it.

You do free up the memory you allocate, which is good.

You don't validate your input values at all. If one of the numbers is negative Bad Things will happen when you clobber memory outside of what you've allocated.

The test i < (greatest + 1) can be restated as i <= greatest.

If I run the program with no parameters, you run into Undefined Behavior in your max function with arr[0].

When allocating space for inputs and outputs in main, you use (argc - 1). You've already computed this and stored it in length, which you use elsewhere. You should use this length value when allocating memory for your arrays.

Why do you pass in and out to sort as int **? You only dereference them to get the underlying pointer. Just pass in the pointers (rather than the address of the pointers) and take the parameters as int *inputs and int *outputs.

You don't check any of your memory allocations for errors.

You do free up the memory you allocate, which is good.

You don't validate your input values at all. If one of the numbers is negative Bad Things will happen when you clobber memory outside of what you've allocated.

The test i < (greatest + 1) can be restated as i <= greatest.

If I run the program with no parameters, you run into Undefined Behavior in your max function with arr[0].

When allocating space for inputs and outputs in main, you use (argc - 1). You've already computed this and stored it in length, which you use elsewhere. You should use this length value when allocating memory for your arrays.

Source Link
1201ProgramAlarm
  • 7.8k
  • 2
  • 22
  • 39

Why do you pass in and out to sort as int **? You only dereference them to get the underlying pointer. Just pass in the pointers (rather than the address of the pointers) and take the parameters as int *inputs and int *outputs.

You don't check any of your memory allocations for errors. You also use a mix of styles. calloc(N, sizeof(int)) in one place, malloc(N * sizeof(int)) in another. Pick one style and stay with it.

You do free up the memory you allocate, which is good.

You don't validate your input values at all. If one of the numbers is negative Bad Things will happen when you clobber memory outside of what you've allocated.

The test i < (greatest + 1) can be restated as i <= greatest.

If I run the program with no parameters, you run into Undefined Behavior in your max function with arr[0].

When allocating space for inputs and outputs in main, you use (argc - 1). You've already computed this and stored it in length, which you use elsewhere. You should use this length value when allocating memory for your arrays.