[問題] 關於getche的問題

看板C_and_CPP作者 (曹操)時間15年前 (2009/03/18 10:57), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
我的目的是希望做一個讀 "XX" 字串的東西 因此跳出條件會是讀到第二次 " 這個字元 不過我發現輸出的時候似乎有點問題 void GetToken() { char token = ' '; // 讀取的字元 char wordChar[100]; memset( wordChar, '\0', sizeof(wordChar) ); int indexOfSave = 0; // 儲存 word 的索引值 indexOfSave = 0; token = getche(); while ( !gIsLineeError && !gIsLineEnd ) { if ( token == 34 ) // 如果讀到 ", 則原封不動的直接印出 { gNumOfQuote++; // 引號數增加一 gIndexOfChar; // 字元數增加一 token = getche(); while ( !gIsLineEnd ) // 讀到另一個 " 為止, 途中必須慎防error { gIndexOfChar++; // 字元數增加一 if ( token == 34 ) { gNumOfQuote--; if ( gNumOfQuote == 0 ) gIsLineEnd = true; } // if() else { wordChar[indexOfSave] = token; indexOfSave++; token = getche(); } // else() cout << wordChar << endl; ////////////////問題行(1) } // if() if ( gIsLineeError ) PrintError( token ); else if ( gIsLineEnd && gNumOfQuote == 0 ) PrintDoubleQuote( wordChar ); indexOfSave = 0; // 初始化 token = ' '; for ( int del = 0 ; del < 100 ; del++ ) word[del] = NULL; memset( wordChar, '\0', sizeof(wordChar) ); } // GetToken() void PrintDoubleQuote( char output[100] ) { int index = 0; cout << "\"" << output << endl; ////////////////問題行(2) cout << "\""; AllInitial(); } // PrintDoubleQuote() 今天我在測試時 假設輸入"33456"(以下為輸出) "33456"33456 "33456 _ (游標會跳到這) 但是第二個"似乎無法輸出? 如果我把問題行(1)拿掉 整個似乎就完全無法輸出了...請問這是? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.57.78.11
文章代碼(AID): #19m6CaJo (C_and_CPP)