I decided to make a program that is looking for TODO: in files. Here is the code:
#include <iostream> #include <fstream> #include <cstdlib> using namespace std; ifstream inFile; const int SIZE = 60; int i,d; string todo[200]; int main() { char filename[SIZE]; string filecontents; cout <<"Place this executable to source folder" << endl <<"and enter filename to start search" << endl <<"filename can't start from space" << endl <<"Maximum count of TODOs is 200."<< endl <<"Maximum size is 60 symbols. Enter q to quit." << endl; while (cin.getline(filename, SIZE)) { if (filename[0] == 'q') { cout << "Terminating...\n"; exit(EXIT_SUCCESS); } else if (filename[0] != ' ') { if (filename[0] != '\n') { inFile.open(filename); if (!inFile.is_open()) { cout << "Can't open file called " << filename << endl; } else { int count = 1; string temp; cout << "Opened file called " << filename << endl << "Searching for todos..." << endl; while (getline(inFile, temp)) { filecontents += temp + '\n'; } while (i < filecontents.size()) { if (filecontents[i] == 'T') { if (filecontents[i+1] == 'O') { if (filecontents[i+2] == 'D') { if (filecontents[i+3] == 'O') { if (filecontents[i+4] == ':') { string temp = ""; char temp2; int temp3 = i + 5; while (temp2 != '\n') { temp += filecontents[temp3]; //TODO: test todo m8 temp2 = filecontents[temp3+1]; ++temp3; } ++d; todo[d] = temp; temp = ""; cout << "Found todo: " << todo[d] << endl; } } } } } i++; } } } else cout << "Please enter correct filename according to rules:\n"; // TODO: another todo as always } else cout << "Please enter correct filename according to rules:\n"; inFile.close(); d = 0; cout<< "Please enter filename: "; } return 0; } When I run this compiled program on my own source code, it only reads the first TODO and only once. How can this be fixed? Or am I just blind and do not see the obvious?
Compiler: Clang ++ LLVM Compiler
System: Fedora 23