I'm doing an assignment for my into to programming in C class using arrays, using fscanf to take integers from a file and then print them. The code will build, but when I run it the program stops working during the Display function on line 31. The error it gives is "exception thrown at 0x00CE50F1 in Project 6.exe: 0xC0000005: Access violation writing location 0x00F4D720." I'm sure im doing something wrong with arrays, as my professor has the array written like "array[count]" not "array[&count]" when printing and scanning, but if I write it like that visual studio underlines "count" and says "expression must have pointer-to-object type". I'm not trying to cheat, i'd like to know what's wrong and how I can make it work.
#define CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int Greeting();
void Display(numchosen, Numptr, array);
int main() {
int numchosen, array[20];
FILE * Numptr;
Numptr = fopen("numInput.txt", "r");
numchosen = Greeting();
Display(numchosen, &array, Numptr);
}
int Greeting() {
int numchosen;
printf("How many integers should I retreive from the file? (1-20)\n");
scanf("%d", &numchosen);
return numchosen;
}
void Display(numchosen, array, Numptr) {
int numprinted, numnum = 1, currentnum, count=0;
for (numprinted = 0; numprinted < numchosen; numprinted++) {
fscanf(Numptr, "%d", &array[&count]);
printf("%d. %d\n", numnum, array[&count]);
numnum ++;
count++;
}
}