I have been trying to learn how to use functions to make my code a lot less repeatitive, but I seem to have something wrong. I tried rereading the guides on the site, as well as looking into my C++ book, and couldn't find why this doesn't work. This is not the complete code, because that is 200 lines or so, so I dropped it down to the first 3 runes I parse for.
If I leave the combo function in, I get nothing that comes after it in the program, I still get the "Reading from:" and the file path, but I don't get a count of how many of each I have. Any help is welcome .
RuneParser.cpp
Code:
#include <iostream>
#include <fstream>
#include <string>
inline void combo(int first, int second)
{
while (first>=3)
{
first-3;
second++;
}
}
int main ( int argc , char ** argv )
{
std::string filename = "C:\\Documents and Settings\\Owner\\My Documents\\Parsing\\Runes.txt";
if (argc >= 2) filename = argv[1];
std::ifstream file( filename.c_str() , std::ios::in );
if (!file.is_open())
std::cout<<"Error opening file";
else
std::cout << "Reading from: " << filename << std::endl;
std::string line;
int el = 0;
int eld = 0;
int tir = 0;
while (getline( file , line ))
{
if (line.empty() || (line == "\r")) continue;
int colon_pos = line.find(':');
std::string rune = line.substr(colon_pos+2,line.size()-colon_pos-7);
if (rune == "El")
el++;
else if (rune == "Eld")
eld++;
else if (rune == "Tir")
tir++;
}
combo(el,eld);
combo(eld,tir);
std::cout<< "El:" << el << endl;
std::cout<< "Eld:" << eld << endl;
std::cout<< "Tir:" << tir << endl;
std::cin.get();
}
Runes.txt
Code:
Number of Items : 39
1: El Rune
3: El Rune
4: Tir Rune
6: Tir Rune
8: Eld Rune
12: Tir Rune
14: El Rune
18: Tir Rune
19: El Rune
21: El Rune
24: Tir Rune
27: Eld Rune
31: El Rune
33: El Rune
35: Eth Rune
36: Tir Rune
37: Tir Rune