I’m trying to scan in a txt file with a string of numbers.

t.txt
123
223
323

<#include stdlib.c>
<#include stdio.c>
<#include string.h>


int main{
char grid[3][3];
int i = 0;

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.

Line 6 is incorrect so I didn't make it past that. Compare this to other working code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.