C++ Maze

Discussion in 'Computer Science & Culture' started by excalade, Feb 6, 2003.

Thread Status:
Not open for further replies.
  1. excalade Registered Member

    Messages:
    1
    Hi folks,
    I need some help here with C++ Files. I need to read a maze from a text file, into a 2-D Char Array. I am having problems doing that. The maze can have maximum 70 ROWS and 22 COLUMNS.

    The text file will look something like this:

    22 7
    **********************
    S *
    *************** ******
    * * E
    *************** **** *
    * *
    **********************

    The first two numbers are the row and the col, are given in the file. How do i access those in my program?
    Also, how do I make the array without '\n' or the other junk chars.
    I tried lots of thing but nothing works. My algorithm is fine, as I tested in a maze i created, but when i read from a file, it gives me errors as I read the file incorrectly, with junk in it. Any help will be very appreciated! Thanks in advance!

    Here is the actual assignment:
    http://cs.senecac.on.ca/~leung/dsa555/assign/a1-w03.html
     
    Last edited: Feb 6, 2003
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. testify Look, a puppy! Registered Senior Member

    Messages:
    508
    Geez man I am just finsihing up my CIS course here at my college, and the first question would be easy enough to figure out, but the second one I would have a hell of a time doing. Probably the best way to do it is to search through all of the characters of each string, and for ever character check the character to the left/right of it and see if there is a space. To check below and above you would have to check that same char #, but the next line in the text file. Check if there is an opening, and if there is the computer should move the marker to that next spot, while at the same time keeping the point where it last saw two spaces (two paths) in a variable (just to make sure if you take one wrong path it can always come back and try the second one).

    To remove the \n from the end of each line in the text file can't you just reduce the string length stored by 1?

    for (int i=1, i<=line[len-1],i++)

    I got to do me a nice scrolling program (a banner scroller) which allowed me to become more familiar with the workings of strings. All I got to say is that after I have used VB strings, C++ strings SUCK!
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. Adam §Þ@ç€ MØnk€¥ Registered Senior Member

    Messages:
    7,415
    I think I'm going to do this one myself, just for something to do.
     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. Mech_The_Muon No, not Moron you twit! Registered Senior Member

    Messages:
    86
    hey, it could be worse, I'm doing C

    Please Register or Log in to view the hidden image!

    strings? what are these strange things?

    Please Register or Log in to view the hidden image!

    OOHHH character arrays with a null character. <insert eye roll> (Gee, I'm not bitter about not having my Java string class

    Please Register or Log in to view the hidden image!

    )
     
  8. testify Look, a puppy! Registered Senior Member

    Messages:
    508
    Aren't C strings MUCH MUCH easier?
     
Thread Status:
Not open for further replies.

Share This Page