※ 引述《justmyself (hsin)》之銘言:
: char* keyword; // Note: keyword can only appear in the beginning of a line
: while ((keyword = _parser.readLine()) != 0) {
: char* str = _parser.getString(keyword);
: if (strcmp(keyword, ".cir") == 0) {
: // [TODO] Record circuit name // return true;
: }
: else
: if (strcmp(keyword, ".input") == 0) {
: if (!parseInputs(str))
: return false;
: }
: 請問一下
: keyword是讀進去一行嗎
: (str應該才是抓出來的keyword吧)
: 那為什麼是strcmp(keyword, ".cir")
: 而不是strcmp(str, ".cir")
: 謝謝~
1. char* Circuit::Parser::readLine()
Read in a line from ifstream Parser::_infile, and then skip white
spaces (' ' or '\t') if there is any in the beginning of line.
The return pointer point to the first non-white-space character.
2. char* Circuit::Parser::getString(char* const str) const
"str" is asserted to point to a non-white-space character.
Starting from "str", look for the first white space character
and replace it with '\0' (end of string), and then keep looking
for a non-white-space character as the next token string.
Return the pointer to the beginning of the next token string.
If the next token string cannot be found (i.e. hit end of line),
return 0.
For example, given a string " People Are Strange " in a file,
readLine() function will return a pointer pointing to 'P'.
char* str = readLine();
Then calling:
char* next = getString(str);
"str" will still point to 'P', but the original string becomes:
" People\0 Are Strange "
and "next" is pointing to 'A'.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.121.131.34