searching arrays
-
Hi all, I am working on a project for school(my final exam grade) and I have having a lot of trouble with it. We are making a hangman game and here is what I have to do. One user inputs the # of letters that the word will be and then enters those words into an array of CHAR's. Then a different user will take the seat and start guessing the letters. How do I search the first array and if a letter is right, fill the second array with the appropriate letter? Does this make any sense? Half my class doesn't get it and the teacher wasn't very helpful. An answer ASAP would be great as my exam is at 1:00 tomorrow. THanks Matt Matt Millican http://www.internetmill.com
-
Hi all, I am working on a project for school(my final exam grade) and I have having a lot of trouble with it. We are making a hangman game and here is what I have to do. One user inputs the # of letters that the word will be and then enters those words into an array of CHAR's. Then a different user will take the seat and start guessing the letters. How do I search the first array and if a letter is right, fill the second array with the appropriate letter? Does this make any sense? Half my class doesn't get it and the teacher wasn't very helpful. An answer ASAP would be great as my exam is at 1:00 tomorrow. THanks Matt Matt Millican http://www.internetmill.com
Use
strchr()
to search a string for a particular character --Mike-- Latest blog entry: *drool* (Alyson) [May 10] Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber "You have Erica on the brain" - Jon Sagara to me -
Hi all, I am working on a project for school(my final exam grade) and I have having a lot of trouble with it. We are making a hangman game and here is what I have to do. One user inputs the # of letters that the word will be and then enters those words into an array of CHAR's. Then a different user will take the seat and start guessing the letters. How do I search the first array and if a letter is right, fill the second array with the appropriate letter? Does this make any sense? Half my class doesn't get it and the teacher wasn't very helpful. An answer ASAP would be great as my exam is at 1:00 tomorrow. THanks Matt Matt Millican http://www.internetmill.com
I'm not sure if I understood you, but that's quite simple. An example: ------------------------------------------ #include #include #include void main() { char singleLetter; bool wordCompleted = false; unsigned int numOfLetters; unsigned int numOfGuessedLetters = 0; cout << "Number of letters: "; cin >> numOfLetters; char* pArray1 = new char[numOfLetters+1]; char* pArray2 = new char[numOfLetters+1]; memset(pArray2,'_',numOfLetters); pArray2[numOfLetters] = '\0'; cout << "Type in the word: "; cin >> pArray1; system("cls"); // Should the other player see what word we've typed in? ;) while(wordCompleted==false) { cout << "Type in a letter: "; cin >> singleLetter; for(unsigned int i=0;i
-
I'm not sure if I understood you, but that's quite simple. An example: ------------------------------------------ #include #include #include void main() { char singleLetter; bool wordCompleted = false; unsigned int numOfLetters; unsigned int numOfGuessedLetters = 0; cout << "Number of letters: "; cin >> numOfLetters; char* pArray1 = new char[numOfLetters+1]; char* pArray2 = new char[numOfLetters+1]; memset(pArray2,'_',numOfLetters); pArray2[numOfLetters] = '\0'; cout << "Type in the word: "; cin >> pArray1; system("cls"); // Should the other player see what word we've typed in? ;) while(wordCompleted==false) { cout << "Type in a letter: "; cin >> singleLetter; for(unsigned int i=0;i
Hi, I changed some stuff around that was incorrect, compiled it and all I got when I ran it was The very end of the program. Any other things? Matt Matt Millican http://www.internetmill.com