Thread: Characters in an Array

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    1

    Question Characters in an Array

    I've been writting a text adventure game and need help with array manipulation. My problem is that I have it so an item and/or monster will be specified to be placed in a certain sector within the array. Lets use a ghost and graveyard for the example....

    I just want the program to understand that the graveyard is the
    only place that the ghost can roam. How do I get it to understand that The Graveyard is where it can go, not...[0][1], [0][2], [0][3], [0][4],ect...............

    How can the program read an array's text (char) information and not the action numbered sectores ([1][3])

    To help understand......

    My array is set up like so....
    ...
    text[0][51][0] = "Dragon Fields";
    text[1][51][0] = "Dragon Fields";
    text[2][51][0] = "A pond";
    text[3][51][0] = "Dragon Fields";
    text[4][51][0] = "A old-looking tree";
    text[5][51][0] = "A cabin";
    text[6][51][0] = "Dragon Fields";
    ...
    Once again, how can the program read I want a dragon roaming in sectors [0][51], [1][51], [3][51], and [6][51]. I just want to put in statment that will tell them that "Dragon Fields" is the only place they can roam. I would do it the other way but this is a 10,000 sector array and would take me forver to enter each sector. Thankyou for your time. Hope you can help.

  2. #2
    Unregistered
    Guest
    try using an if statement to see if text[x][y][z] == 'Dragon Fields' and only move if it does

  3. #3
    Unregistered
    Guest

    Arrow Nope

    That doesn't work.

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    Dont cross post!
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  5. #5
    >>try using an if statement to see if text[x][y][z] == 'Dragon Fields' and only move if it does

    The concept works just fine. The Syntax is just wrong. You're looking for:

    if (strcmp(text[x][y][0], "Dragon Fields") == 0) //etc

    You cant compare strings with ==, you have to use strcmp() or something simular.

    >>Dont cross post!

    I second that. Its against board rules. The other post was in the Game board under "Unregistered". Took me a second to find it actually. Please dont do that.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. erase all characters in a character array?
    By diddy02 in forum C Programming
    Replies: 4
    Last Post: 11-20-2008, 05:30 PM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  3. storing a pattern of characters into a 2D array
    By haroonie in forum C Programming
    Replies: 2
    Last Post: 04-20-2005, 05:19 AM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. Can a string be converted to an array of characters?
    By supaben34 in forum C++ Programming
    Replies: 8
    Last Post: 12-08-2002, 12:18 PM