I'm making a string parser program to find specific words within large character arrays. Here's what I've got:
I try to indent, comment, space, etc. as much as possible. The problem is that it recognizes "get" but not "key" or "sword" it recognizes "getkey" and "getsword" though. I use Visual C++ 6.0 on Windows 98. Any help would be nice.Code:#include <iostream.h> #include <string.h> #include <conio.h> #include <dos.h> #include <windows.h> char com[41]; bool key = true, sword = true, shield = true, cup = true; // Item statuses void cls() { COORD coordScreen = { 0, 0 }; // A bunch of Windows API crud, ignore DWORD cCharsWritten; CONSOLE_SCREEN_BUFFER_INFO csbi; DWORD dwConSize; HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hConsole, &csbi); dwConSize = csbi.dwSize.X * csbi.dwSize.Y; FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten); GetConsoleScreenBufferInfo(hConsole, &csbi); FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten); SetConsoleCursorPosition(hConsole, coordScreen); } void items() { cout << endl; if (key == true) { // If there's a key cout << "There is a key on the ground.\n"; } if (sword == true) { // If there's a sword cout << "There is a sword on the ground.\n"; } if (shield == true) { // If there's a shield cout << "There is a shield on the ground.\n"; } if (cup == true) { // If there's a cup cout << "There is a cup on the ground.\n"; } cout << endl; } void main() { int i = 0, n = 0; // For loop variables cout << "String Parser\nBy: Scott A. Hand" << endl; Sleep(750); // Pause cls(); // Clear the screen items(); // Initialize item status and screen cout << "Enter command.\n> "; cin >> com; // Get user input for (i = 0;i <= 40;i++) { if ((com[i] == 'g' && com[i+1] == 'e' && com[i+2] == 't') || com[i] == 'G' && com[i+1] == 'E' && com[i+2] == 'T') { // If the user has typed "get" anywhere cout << "You have typed 'get'" << endl; // Debugging statement for (n = 0;n < 40;n++) { // Loop to catch the argument if (com[n] == 'k' && com[n+1] == 'e' && com[n+2] == 'y') { // If the argument's "key"0 key = false; // Means it shouldn't show the key. cout << "You picked up a key.\n"; // Statement to tell me that this works. goto goodbye; // Required to speed things up } if (com[n] == 's' && com[n+1] == 'w' && com[n+2] == 'o' && com[n+3] == 'r' && com[n+4] == 'd') { // If the argument's "key"0 sword = false; // Means it shouldn't show the sword. cout << "You picked up a sword.\n"; // Statement to tell me that this works. goto goodbye; // Required to speed things up } } } } exit(0); goodbye: cout << "Goodbye!\n"; }



LinkBack URL
About LinkBacks


