Hey Guys,
I'm trying to read individual characters from a file, store them in two arrays then print out the arrays. The input file looks something like this
7
1 5
0 1
2 4
3 7
0 2
5 9
0 3
With the first number being the length of the arrays and the first column being the first array and the second array being the second column. When I run the code below I get a seg fault on the line arrOwner = fgetc(infile);
#include <stdio.h>
int main(void){
int j,i,temp,numSegs = 0;
FILE *infile = fopen("input.txt","r");
fscanf(infile,"%d", &numSegs);
int arrOwner[numSegs];
int arrLength[numSegs];
while(!feof (infile)){
arrOwner[i] = fgetc(infile);
arrLength[i] = fgetc(infile);
i++;
}
while(numSegs > 0){
printf("%d", arrOwner[j]);
printf("%d", arrLength[j]);
j++;
numSegs--;
}
}