After long hours of testing I believe I have finally pulled something together...but still one of the major trouble I frequently run into during the trials are reading the characters from the target external txt file, I used '#' to represent alive cells, and '-' (for come reason my compiler has poor recognition of space character ' '). But even with '-', there still seem to be strange error momentarily, meaning it reads without error only when the dimension is within 25 by 25, which I can't figure out why.
why?
why!
Code:
void Read_in (void)
{
//local variables
FILE *input_file;
char file_name[100];
int x, y;
char temp;
//get filename from user
printf("Enter name of file: ");
scanf("%s", file_name);
// strcat(Fname,".txt");
//open file
input_file = fopen(file_name, "r");
if (input_file == NULL)
{
printf("Could not open input file\n");
exit(1);
}
//read data into array
for (y=0 ; y<YMAX; y++)
{
for (x=0; x<XMAX; x++)
{
temp = getc(input_file);
if (temp == EOF)
{
printf("Unexpected end-of-file in %s", file_name);
//printf("End character is %c at [%i][%i]", temp, y, x);
return;
}
if (temp == '#')
board [y][x] = 1;
else if (temp == '-')
board [y][x] = 0;
else
{
//printf("Unknown character found in file: [%i] [%i]", y, x);
printf("Unknown character found, that character is %c at [%i][%i]", temp, y, x);
return;
}
}
getc(input_file); //throw away newline character
}
fclose(input_file);
}