I’m trying to scan in a txt file with a string of numbers.
t.txt
123
223
323
File *f = fopen(“t.txt”, “r”)
while (i != 3){
for (int j = 0; j < 3; j++){
fscanf(f, “%1c”, &grid[i][j]);
}
i++;
}
But it prints a segment fault.
I’m trying to scan in a txt file with a string of numbers.
t.txt
123
223
323
File *f = fopen(“t.txt”, “r”)
while (i != 3){
for (int j = 0; j < 3; j++){
fscanf(f, “%1c”, &grid[i][j]);
}
i++;
}
But it prints a segment fault.
So much left unwritten. I don't see how grid was declared, the value i might not be initialized and there are usually some references to which C library will be used in the first few lines. I'll write incomplete code means I would be guessing here.
There isn't enough code for me to compile even with that. I suggest you single step the code in the usual debugger to see why it fails.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.