Valera (valera) wrote,
Valera
valera

  • Music:

c++ nerndess

for some reason, it reads one more line than i need it to. it's like it notices something that cat -n and wc -l don't notice... =\. but that's where strcmp line comes in handy.

#include <fstream>

using namespace std;

int main(){
        char buffer[1024];
        int counter=1;
        ifstream inFile("report.txt");
        ofstream outFile("report2.txt");


        while( ! inFile.eof() ) {       
                inFile.getline(buffer,1024);
                if(strcmp(buffer,"")){
                        outFile <<  counter++ <<") <a href=\"/" << buffer << "\">" << buffer << "</a><br>\n";
                        }
        } 
        inFile.close();
        outFile.close();
        return 0;
}
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments