dimanche 20 janvier 2019

Check for multi comment in a text file and print it out

I am trying to loop through a text file, scan it and find multi comments that starts with #| and end with |# and print it out. I am using get function to loop through each characters and the peek function to check for the next character. currently my code is not recognizing the ending comments. Please help.

I have tried looping through each characters comparing it with the multi comments and store it in a vector

void Scanner::readingThroughTheFiles(ifstream &inFile) { ``lineNumber = 0; ``inFile.open(fileName); `` while (!inFile.eof()) { ``char c = '\0'; ``while (inFile.get(c)) { // loop getting single characters ``tokens = c; ``isAText(inFile); ``isAWord(inFile); ``//isAComment(inFile); ``if(c == '\n') { ``lineNumber++; `` } ``if (c == '#' && inFile.peek() == '|') { ``char next = inFile.peek(); ``multipleComment += c; `` multipleComment += next; ``char c = tokens; ``while (inFile.get(c)) { ``multipleComment += c; ``if (tokens == '|' && next == '#') ` { tokenTypes.push_back(multipleComment); values.push_back("COMMENT"); //lineNumbers.push_back(lineNumber); multipleComment.clear(); } } }

Aucun commentaire:

Enregistrer un commentaire