I have 2 problems, the code posted here is a commandline to a mud, it works, but not as good as it should. is there any way to make it better? some better way to split up the words into diferent variables? I sometimes, not allways, get an error massage after I run the program with shows me some hex codes which I dont understand. its mostly only when I type one word, like "time" or "exit" how can these accur sometimes and not allways?
to my second problem I wonder how I can make an "if" detect if there is written anything in a variable so I can make it print eighter the variable or a text that for instence says "nothing.." if anyone bothers to read the code and give me some pointers I apriciate it:P thx.
the commandline code:
Code:#include <iostream.h> #include <conio.h> #include <dos.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <time.h> /*functions*/ void basic(); void kom(char per[100]); void get(); void wear(); void time(); /*GLOBALE variables*/ char first[20], second[20], third[20]; /*main funktion*/ int main(void) { char per[100]; start: cout << "\nYour command? "; cin.get(per,100); cin.ignore(); kom(per); goto start; } /*splits up the word into variabels*/ void kom(char per[100]) { int a=0, c=0; do{ if (per[c] == ' ') {break;} else { first[a] = per [c]; a++; } c++; } while (1); c++; a=0; do{ if (per[c] == ' ') {break;} else { second[a] = per [c]; a++; } c++; } while (1); c++; a=0; do{ if (per[c] == ' ') {break;} else { third[a] = per [c]; a++; } c++; } while (1); basic(); } void basic() { getch(); if (!strcmp(first, "wear")) {wear();} else if (!strcmp(first, "get")) {get();} else if (!strcmp(first, "exit")) {exit(1);} else if (!strcmp(first, "time")) {time();} else {cout << "\n What? Who? When!?";} } /*checks the second word and exacutes the command*/ void wear() { if (!strcmp(second, "shirt")) {cout << "\nYou wear the ragget old shirt";} else if (!strcmp(second, "pants")) {cout << "\nYou wear the pants";} else if (!strcmp(second, "caps")) {cout << "\nYou wear the red caps";} else if (!strcmp(second, "boots")) {cout << "\nYou wear the smooth, black boots";} else {cout << "\nYou dont have that to wear!";} getch(); } /*checks the second word and exacutes the command*/ void get() { if (!strcmp(second, "shirt")) {cout << "\nYou get a ragget old shirt";} else if (!strcmp(second, "pants")) {cout << "\nYou get tha pants";} else if (!strcmp(second, "caps")) {cout << "\nYou get the red caps";} else if (!strcmp(second, "boots")) {cout << "\nYou get a pair of smooth, black boots.";} else {cout << "\nYou cant see that item anywhere";} getch(); } /*prints the time and date*/ void time() { time_t t; time(&t); cout << "Today's date and time: " << ctime(&t); }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.
and so much more simple to handle then my program which the compiler dont like.