Program reads the contents of a file. The very first number in the file is the amount of numbers the file has below.
I have to store all those numbers, but after creating an array of such size, the program terminates. Is there are any to work around this? Or am i doing it the wrong way?
#include <stdio.h>
#define BUFFER_SIZE 16
int main(void)
{
FILE *file = fopen("sequence.txt", "r");
char buffer[BUFFER_SIZE];
fgets(buffer, BUFFER_SIZE, file);
int number_amount;
sscanf(buffer, "%d", &number_amount);
printf("OK"); // <-- Only this OK gets printed out.
int number_array[number_amount];
printf("OK");
int current_number;
for (int index = 0; index < number_amount; index++)
{
fgets(buffer, BUFFER_SIZE, file);
sscanf(buffer, "%d", ¤t_number);
number_array[index] = current_number;
}
fclose(file);
printf("OK");
return 0;
}