I am trying to write from a txt file to a 2D array the ONE_LINE array seems to write over and over again. I was also trying to use the to two 17's as the array dimensions. Any Ideas

Thanks

Sean

THIS IS THE CONTENTS OF THE TXT FILE


17
17
XXXXXXXXXXXXXXXXX
X XX X X
X X X XXXXXXXX
X XXX XXXXX XX
X X XX XX XX
X X XXXX XX XX XX
X X XXXXX XX
XXX XXXXXX
XXXXX XXX XX XX
X X X X X XX
X XX XX X XXX
X XXXXX XXX X X X
X XX X X X X
X XXXXX X X X X
X X XXXXXX X X X
X XX X X
XXXXXXXXXXXXXXXXX


#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_CHARACTERS 20

int i,j;
int counter;

char one_line[MAX_CHARACTERS] ; /* Array used to store line */


int colcount;
int rowcount;

char tempchar;

main()

{

//int mazerow, mazecol;

/* pointer to the File */
FILE *fp_in ;
FILE *fp_other ;
char temp_array[mazerow];


char working_array [mazerow][mazecol];


/* Open the file for reading */

if ( (fp_in=fopen("maze.txt","r") )==NULL )

{
puts( "Error in opening file.txt" ) ;
}

else

/* Read at most MAX_CHARACTERS-1 characters from the file
or until a new line character (\n) is read
or the end of file occurs. */

/* counts lines as they are printed */

counter = 0;

while (fgets( one_line,MAX_CHARACTERS,fp_in )!=NULL )
{
// gets the value of line one as an integer
if (counter ==0)
{
mazerow = strcpy(one_line);
printf("the value rows = " "%i" "\n",mazerow);
}
// gets the value of line two as an integer
if (counter ==1)
{
mazecol = strcpy(one_line);
printf("the value col = " "%i" "\n",mazecol);
}
// prints out array one_line (contents of the file)
printf("%s",one_line ) ;
counter++;

}// END WHILE

printf("\n" "the number of bytes in the file is %d",
sizeof(one_line));
printf ("\n" "counter is %d" "\n", counter);

fclose( fp_in );// finished printing so file is closed


//working_array [mazerow][mazecol]=0;


if ( (fp_other=fopen("maze.txt","r") )==NULL )

{
puts( "Error in opening file.txt" ) ;
}
else
{





while (fgets( temp_array,mazerow ,fp_other )!=NULL)
{
for (colcount=0; colcount <mazerow; colcount++)
{
tempchar= temp_array[colcount];
working_array [rowcount][colcount]=tempchar;
printf("%s",temp_array);
}
rowcount++;

}
}
printf("Final val of wking ar 17 14 is %c", working_array [17][17]);

fclose( fp_other );// finished populating

return 0;}//end of main