Created
          April 3, 2009 13:22 
        
      - 
      
- 
        Save jpemberthy/89746 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include <iostream> | |
| #include <fstream> | |
| #include <string> | |
| using namespace::std; | |
| string StringStrip(string& s); | |
| string trim(string&,const string&); | |
| int main(int argc, char *argv[]){ | |
| ifstream f; | |
| ofstream fOut; | |
| string line; | |
| if(argc < 2){//no pasaron archivo para parsear | |
| cout << "No file to parse" << endl; | |
| return 0; | |
| } | |
| f.open(argv[1]); | |
| if(!f){ | |
| cout << "Error loading: " << argv[1] << endl; | |
| } else { | |
| int cont = 0; | |
| fOut.open ("Parsed.out"); | |
| while(!f.eof()){ | |
| getline(f,line); | |
| fOut << StringStrip(line) << endl; | |
| cout << "Processing Line: " << cont << endl; | |
| cont++; | |
| } | |
| fOut.close(); | |
| f.close(); | |
| } | |
| return 0; | |
| } | |
| string trim(string& s,const string& drop = " "){ | |
| string r=s.erase(s.find_last_not_of(drop)+1); | |
| return r.erase(0,r.find_first_not_of(drop)); | |
| } | |
| string StringStrip(string& s){ | |
| string str = trim(s); | |
| string orgS = "";//string organizada. | |
| bool addSpace = true; | |
| for(unsigned int i = 0; i < str.length(); i++){ | |
| if(str[i] == ' '){ | |
| if(addSpace){ | |
| addSpace = false; | |
| orgS += str[i]; | |
| } | |
| } else { | |
| orgS += str[i]; | |
| addSpace = true; | |
| } | |
| } | |
| return orgS; | |
| } | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment