Reading Characters from file into multi-dimensional array
I'm having troubles reading characters from a file into a multi-dimensional array. I'm able to read them in but the output isn't correct when displaying the characters in the array. This is for a wordfind program and I need to read each letter of the puzzle into a spot in a multi-dimensional array and I can do some comparisons to see if a word exists in the puzzle. Here's my code for reading the characters into the array.
Code:
#include <stdio.h>
int main()
{
int i, j, c, row, col;
FILE *fp;
row = col = 15;
fp = fopen("cashiers.txt", "r");
// read letters into array
char array[row][col];
for (i = 0; i <= row - 1; i++)
for (j = 0; j <= col - 1; j++)
array[i][j] = ' ';
while ((c = getc(fp)) != EOF)
{
for (i = 0; i <= row - 1; i++)
for (j = 0; j <= col - 1; j++)
if((c != '\n') && (c != '\r'))
array[i][j] = c;
}
for(i = 0; i <= row - 1; i++)
{
for(j = 0; j <= col - 1; j++)
printf("%c", array[i][j]);
printf("\n");
}
return 0;
}
Thanks for any help you can offer.