I am working on a homework assignment and I can not figure out how to pass the information from my file into my program to use. We are working on the game of life and 2D arrays, and we were asked to use command line arguments to read a separate file that has the first two lines the height and width of the 2D array and then the rest are asterisks and spaces that we convert to 0s and 1s to play the Game of Life.
I have tried both fscanf
and fgets
but I can't get either one to work out for me.
int main(int argc, char*argv[])
{
FILE * fileTable;
fileTable = fopen(argv[1], "r");
if(fileTable==NULL)
{
printf("file not found!!!\n");
exit(1);
}
int i = 0;
double g;
char * listA[1000];
fgets(listA, 50, fileTable);
fclose(fileTable);
When I use fgets
, I end up with an error basically telling me I am doing it wrong and using the wrong types and whatnot, but when I use scanf
inside of a while loop using feof
, it never exits the loop.
int i = 0;
double g;
fscanf(fileTable, %lf, &g);
while(!(feof(fileTable)))
{
fscanf(fileTable, "%lf", &g);
i++;
}
fclose(fileTable);