Saturday, May 22, 2010

Calling all C experts!?

I am trying to finish a small program on an adventure game written in C and am doing very badly. Part of the requirements is to write an array of poointers to locations within the game. Some of the code I have ised so far is below.





THIS IS LOCATED OUTSIDE THE INT MAIN (VOID)





struct loc {


char* desc;


};





THEN WITHIN THE INT MAIN (VOID), I HAVE AS WELL AS OTHER CODE THIS:





struct loc*ls[8];





loc[0].desc = "at the entrance to the cave.\n\n";


loc[1].desc = "in the King's Hall. \nThe Troll King is sleeping on his throne.\n\n";


loc[2].desc = NULL;


loc[3].desc = NULL;


loc[4].desc = NULL;


loc[5].desc = "in a dry cave.\n\n";


loc[6].desc = NULL;


loc[7].desc = "in a narrow passageway.\n\n";





My questions is:


When users move north, south etc, they accumulate a score, if the score matches 5, it says "you are in a cave", if it matches a null value it just says "you are in a maze of twisty passages" How do I set


this up for Null and does the above code look correct so far?

Calling all C experts!?
shouldn't


loc[0].desc = "at the entrance to the cave.\n\n";%26lt;/code%26gt;


etc, be


ls[0].desc = "at the entrance to the cave.\n\n";





and I would just do this to test for NULL:


if (ls[score].desc==NULL)


{


    printf("you are in a maze of twisty passages");


}


else


{


    printf(ls[score].desc);


}
Reply:if(!loc[4].desc)
Reply:Im not sure what your asking, are you asking how to set those NULL values to do something special?





And your code looks decent, due to not being able to see the rest of your code that looks pretty much clean as far as a quick glance can see.

survey for cash

No comments:

Post a Comment