Did you fix this?Originally Posted by jlou
yes.
You also need to allocate space for tmp. Try using:Originally Posted by Pat010101Code:char tmp[10];
I added this:
It had not affect, i still couldnt use chocie 1.Code:char tmp[10];
Maybe re-post your code. I removed the goto, changed the tmp declaration, used maxWord instead of 2, and changed <= to <. I ran the code, and while it's not perfect, it works.
Here:
Code:#include <iostream> #include <stdlib.h> #include <string.h> #define maxWord 3 int main(int argc, char *argv[]) { char* word[maxWord]; char* def[2]; char tmp[10]; char test; word [0] = "1"; def [0] = "ab"; word [1] = "2"; def [1] = "abc"; word [2] = "3"; def [2] = "abcd"; cout << "Enter 1,2 or 3: "; cin >> tmp; for (int i = 0; i < maxWord; i++) { if(strcmp(tmp, word[i]) == 0) cout << def[i]; } test: goto test; system("PAUSE"); return 0; }
Three problems:
- You forgot to change def[2] to def[maxWord].
- You need to remove the goto, it causes an infinite loop, possibly before your output is flushed to the console.
- Minor detail, but why does your compiler allow you to use <iostream> and cout without qualifying the std namespace? Are you changing your header so you won't get flamed.
thanks, i got it to work.