Hi, can anyone out help me with my assignment which is to read an image file of a maze and find an exit of it.

As I'm still kinda of new @ C programming, I'm having problems even reading the image onto C.

Cheers
Ming

Well what format is this image file in?
BMP format perhaps?

Though most newbies start with mazes defined in ascii art, like this

#S########
#        #
######   #
#        #
#E########

Find a route through the maze from S to E

Salem the image will be of .gif or .bmp format. I can't seems to even find the correct library or codes to even load it.

Cheers
Ming

Salem, after reading all of the web page contents, I'm still having problems even writing out the initial program.

Cos i not so sure which library to use, for normal standard program is #include Studio.h or math.h for calculation etc.

But for this instance, I am getting more confuse. Please advice me about how to go about writing the program. If its possible, can you show me examples instead.

Cheers
ming

Perhaps start with an ASCII-art map like I posted above, and then develop the maze solving code.

Colin,

I tried reading that webpage many time and I still don't have the slightest idea about how to go about it.

Is it possible that U can write a little portion about how to read an .bmp file script for me to take a look and its easier for me to understand.

Cheers
Ming

FILE *fp = fopen( "file.bmp", "rb" ); This opens the file

unsigned char buff[10];
size_t n = fread( buff, sizeof(buff[0]), sizeof(buff), fp );

This reads 10 bytes from the file.

10 is obviously just an example, but you can read the documentation to find out how big a BMPHEADER structure is, and read that number of bytes instead. Having got that, you get vital information such as
- the width and height of the image
- the number of bits in each pixel
- whether there is a colour table in the file.

You then skip the optional colour table (say by using fseek), then you can start looping reading image data, based on your knowledge of the width, height and bpp of the image format.

Salem, Thanks for getting back to me on this. But when U say

unsigned char buff[10];
size_t n = fread( buff, sizeof(buff[0]), sizeof(buff), fp );
This reads 10 bytes from the file.

Do U mean that this command only allow me to read only 10bytes of data from the file only?

And the .bmp file i'm reading is simply in black and white.

Pls look at http://hereandabove.com/maze/mazeorig.form.html.

And u will have a clearer idea what sort of image i'm trying to read.

Cheers & Thanks
Ming

> Do U mean that this command only allow me to read only 10bytes of data from the file only?
That was an example - read the documentation to decide how many to read.

Short of actually posting the actual code en-masse (which isn't going to happen), I don't know what else to tell you. You can read from 1 byte to the whole file, the choice is yours.

google "let us C yashwant kanetkar filetype:pdf" and in the book goto "graphics programming". I guarantee that u'll understand it perfectly well. And read drawing shapes b4 moving to viewing bitmap

Edited 5 Years Ago by timetraveller92: n/a

This article has been dead for over six months. Start a new discussion instead.