Feb 28, 2016 09:29 AM
(This post was last modified: Feb 28, 2016 02:29 PM by Bulgarian.)
SolvedFirstProblem (Click to View)
solvedSecondProblem (Click to View)
Another one...
Open a text file that contains two numbers/dimensions separated by either a comma or a space, followed by a block of what appears to be a maze from character #.
There is one 's' char and one 'g' char, these are start and goal. # is the wall of the maze.
If there is no such file exit the program. If the numbers/dimensions are less than 10, exit the program.
The first number represents the rows of the maze, the second number represents the columns of the maze.
If the dimensions pass, then check each line to see if there is any other character than 's', 'g', '#'. If any other characters are presents the program should exit. If not, display the maze contained in the text file surrounded by a frame. The top and bottom should be dashes the left and right should be | pipe chars.
This is what I've tried so far...
Both numbers get allocated into the variables!
Oh and a sample file for the maze.tx is:
solvedSecondProblem (Click to View)
Another one...
Open a text file that contains two numbers/dimensions separated by either a comma or a space, followed by a block of what appears to be a maze from character #.
There is one 's' char and one 'g' char, these are start and goal. # is the wall of the maze.
If there is no such file exit the program. If the numbers/dimensions are less than 10, exit the program.
The first number represents the rows of the maze, the second number represents the columns of the maze.
If the dimensions pass, then check each line to see if there is any other character than 's', 'g', '#'. If any other characters are presents the program should exit. If not, display the maze contained in the text file surrounded by a frame. The top and bottom should be dashes the left and right should be | pipe chars.
This is what I've tried so far...
Quote:#include <stdio.h>
int main ()
{
FILE file;
char c;
int n = 0;
char fLine [100];
int rows = 0;
int colms = 0;
file = fopen("maze.txt", "r");
if (file==NULL){
perror ("Error reading file");
return(-1);
}
else if(fgets (fLine , 100 , file) != NULL ){
puts (fLine);
sscanf (fLine,"%i %i",&rows,&colms);
if ( rows <= 10 || colms <= 10){
printf("Dimensions are too small");
fclose (file);
return(-1);
}
else
printf("%i %i\n", rows, colms);
printf("There are %i rows \n", rows);
printf("There are %i columns \n", colms);
}
/ if (c != 's' || 'g' || '#')
printf("You have invalid character");
else
{
do {
printf("%c", c);
} while (c != EOF);
*/
}
Both numbers get allocated into the variables!
Oh and a sample file for the maze.tx is:
Quote:12, 15
####s### ####### #########
####### ##### ###### ### #
## ####### ### ###### ####
#### ########## ###### ###
# ####### ######## #### ##
#### ######g######## #####


