作者fairyflame (妖精火燄)
看板EE_DSnP
標題[問題] addHistory function
時間Sun Mar 30 23:06:36 2008
這個應該跟作業無關 我只是純粹想知道code寫的意義而已@__@"
在addhistory這個function裡
// remove ' ' at the end
char* tmp = _readBufEnd - 1;
while ((tmp >= _readBuf) && (*tmp == ' ')) *(tmp--) = 0;
// remove ' ' in the beginning
tmp = _readBuf;
while (*tmp == ' ') ++tmp;
// add to _history
if (*tmp != 0) {
addHistoryStr(tmp);
_history[++_historySize].clear();
_historyIdx = _historySize;
}
在remove ' 'at the end裡
*(tmp--) = 0;的意義到底是什麼呢@@?
是作為一個flag當add history時不要把它給加進去
那為什麼remove ' 'in the beginning 就不用令*(tmp)=0呢?
當判斷式if (*tmp != 0)時 那其它原本輸入若有0的字串不會有問題嗎@@"
雖然跟作業不太有太大的關係 但還是想知道為什麼想這樣寫
懇請開示 謝謝<(_ _)>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.4.235