- 4th Jul 2019
- 01:18 am
- Ali Akavis
Question : A program that displays all the items in the first two locations of the ‘Colossal Cave Adventure’
C Language Program :
//program to display all the items contained in the first two locations of cave #include < stdio.h > //define the structure which contains two components //One is short name and the other is description //Both are character type of length upto 8 and 50 respectively structcolossal_cave { char name[10]; char description[50]; }; int main() { //define an array of structure of name info which is of length 4 //put the name and description for each array element structcolossal_cave info[4] = { { "keys", "There are some keys on the groun here." }, { "lamp", "There is a shiny brass lamp nearby." }, { "food", "There is tasty food here." }, { "bottle", "There is a bottle of water here." } }; int i; //the next line is for showing title "short name" and "description"...if want to remove delete the next line printf("%s\t%s\n\n", "Shortname", "Long description"); //print all the 4 components of the array of structure for (i = 0; i < 4; i++) { printf("%s\t\t%s\n", info[i].name, info[i].description); } }