-2

Maybe I'm still tired, but I can't seem to figure out why this keeps crashing after the second input. No point in sorting it if it keeps breaking before the values are entered.

#include <stdio.h>

#define MAX 5

int main(){

  int input[MAX], output[MAX], i, j, high;

  printf("Please enter 5 exam scores.\n");
  for (i=0; i<MAX; i++){
      scanf("%d\n", input[i]);
  }
  for(i=0; i<MAX; i++)
      printf("%d\n", input[i]);

  return 0;
}
Nick T
  • 25,754
  • 12
  • 83
  • 121
  • 1
    Yes, the debugger can tell you why. Compile with all warnings and debug info : `gcc -Wall -Wextra -g` with [GCC](http://gcc.gnu.org/) then **use the debugger** `gdb` – Basile Starynkevitch Oct 29 '17 at 15:40
  • 1
    BTW, `MAX` is a commonly used macro name. I recommend using something different and longer, perhaps `MY_DIM` – Basile Starynkevitch Oct 29 '17 at 15:41
  • `scanf("%d", &input[i]);` And for future working on `scanf()` if you use `%c` add leading space in it, [see](https://stackoverflow.com/questions/3744776/simple-c-scanf-does-not-work) – EsmaeelE Oct 29 '17 at 15:51

1 Answers1

1

The problem is occurring because you forgot to put '&' before input[i]:

scanf("%d\n", input[i]);
///          ^    missing &
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
H.S.
  • 11,654
  • 2
  • 15
  • 32