lambs... a couple of points on your code:
>ch and EOF
fgetc() returns an int, so you must assign it's return to an int, not a char as you have done. This is important because EOF is an int with value of -1. If you assign to a char, you will loose the ability to test against EOF correctly.
>atoi()
For what your doing, you don't need to use atoi(), it's extra effort with no gain, imo.
Here's a version that does what you want (I think it does anyway, if not you can adapt it to suit). It doesn't do any bounds checking on the array, a thing which should do be done.
Code:
#include <stdio.h>
#include <ctype.h>
int main(void)
{
FILE *fp;
int row, col, c;
char map[2][10] = { { 0, 0 } };
if ((fp = fopen("map01.txt", "r")) == NULL)
{
perror("map01.txt");
return(1);
}
row = 0;
col = 0;
while ((c = fgetc(fp)) != EOF)
{
if (c == '\n')
{
row++;
col = 0;
}
else
{
if (isdigit(c))
{
map[row][col] = (char) (c - '0');
col++;
}
}
}
fclose(fp);
for (row = 0; row < 2; row++)
for (col = 0; col < 10; col++)
printf("map[%d][%d] = %02x\n", row, col, map[row][col]);
return(0);
}
/* The input file contains:
123456
789012
And the output looks like this:
map[0][0] = 01
map[0][1] = 02
map[0][2] = 03
map[0][3] = 04
map[0][4] = 05
map[0][5] = 06
map[0][6] = 00
map[0][7] = 00
map[0][8] = 00
map[0][9] = 00
map[1][0] = 07
map[1][1] = 08
map[1][2] = 09
map[1][3] = 00
map[1][4] = 01
map[1][5] = 02
map[1][6] = 00
map[1][7] = 00
map[1][8] = 00
map[1][9] = 00
*/