作者tzuci6649 (曹操)
看板C_and_CPP
标题[问题] 关於getche的问题
时间Wed Mar 18 10:57:39 2009
我的目的是希望做一个读 "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