Files are generally well formatted, you should be able to use fscanf without any "issues" here:
Code:
char array[M][N]; /* M and N are macros for the size */
FILE *fp;
int i, j;
int x;
/* Open fp with fopen here */
/* Check for success */
if (!fp) {
perror("File open failure");
}
else {
while (fscanf(fp, "%d%d%d", &i, &j, &x) == 3) {
/* Verify indices */
if (i < 0 || i >= M || j < 0 || j >= N) {
fprintf(stderr, "Index out of range\n");
continue;
}
array[i][j] = x;
}
/* Check to see why we stopped */
if (!feof(fp)) {
if (ferror(fp) {
fprintf(stderr, "Input error\n");
}
else {
fprintf(stderr, "Invalid input\n");
}
}
}