For the life of me I cant see why this doesnt work! Im trying to read in a 4 by 4 array of integers from a txt file. Any suggestions as to why its not working?
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE* pFileHandle;
char filename[15];
int array[4][4];
int i;
int j;
printf("Please enter the name of the file you wish to use:\n");
scanf("%s", filename);
//error test
if((pFileHandle = fopen(filename, "r")) == NULL)
{
printf("Unable to open file : %s\n", filename);
return 0;
}
else
//scan the contents of the input file to the array
{
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
fscanf(pFileHandle, "%i\t", array[i][j]);
}
}
}
fclose(pFileHandle);
}