[Edit] Read a few posts down.
Ok - I've been working on an excel project for a few days. Now I need to transpot theyse 10x10 excel grids to things that my parser will understand. However, my parser is incorrect, or more, I'm an idiot and built it poorly.
My code is very straightforward, open a file, take the files contents, parse it, open another file, output the parsed data. My problem is, a 10x10 grid should have 100 characters. For some odd reason, I'm getting poorly parsed results.
My code:
Code:
#include <iostream>
#include <string>
#include <windows>
#include <fstream>
using namespace std;
string PARSER(string tbp);
string Load();
void OP(string a);
int main() {
string a;
a=PARSER(Load());
cout << a;
OP(a);
}
string Load() {
char gur[1001];
string gar;
string MAPPATH="C:\\Info.txt";
int x;
ifstream file_in(MAPPATH.c_str(), ios::nocreate);
for(x=0; x < 1000; x++)
file_in.get(gur[x]);
gar+=gur;
return gar;
}
string PARSER(string tbp) {
int x;
char m[1];
string agr;
for(x=0; x < tbp.length(); x++) {
m[1] = tbp[x];
if(m[1] == '\n')
goto done;
if(m[1] == ' ')
goto done;
if(m[1] == '\t')
agr+='B';
if(m[1] == 'R')
agr+='R';
done:
}
return agr;
}
void OP(string a) {
string MAPPATH="C:\\Output.txt";
int x;
ofstream file_out(MAPPATH.c_str(), ios::nocreate);
file_out << a;
}
As I said, very straightforward.
And my parser data (three of them as an example, they're all the same length
1:
Code:
R R R R R R
R
R
R R R R
R R R
R R R
R R R
R R R R
R R R R
R R R R R R R R
2:
Code:
R R R R R R
R R R R R
R R R R R
R R R
R
R R R R
R R R R
R R R R
R R R R R R R R
3:
Code:
R R R R R R R R
R R R
R R
R R R
R R
R R
R R R
R R
R R
R R R R R R R R
And the output is respectively:
Code:
1: RBRBBBRBRBBBRBRBBBBRBBBBBBBBBRBBBBBRBRBBBRBBBBBRRBRBBBBBBBBRRBRBBBBBBBBRRBRBBBBBBBBRRBRBBBRBBBBBRRBRBBBRBBBBBRRBRBBBRBRBRBRBRBR
2: RBRBBBRBRBBBRBRRBRBBBRBRBBBBRRBRBBBRBRBBBBRRBRBBBBBBBBRBBBBRBBBBBBBBBBBBBBRBBBBBBBRBRBRRBBBBBBBRBRBRRBBBBBBBRBRBRRBRBBBRBRBRBRBRBR
3: RBRBRBRBRBRBBBRBRRBBBBBBBBRBRRBBBBBBBBBRRBBRBBBBBBBRRBBBBBBBBBRRBBBBBBBBBRRBBBRBBBBBBRRBBBBBBBBBRRBBBBBBBBBRRBRBRBRBRBRBBBRBR
As is visible, the output is different in character length. They should all have exactly 100 characters. Oh, and reguarding the goto, its just so the computer doesnt need to run uneccesary if checks.
Thanks for reading this, and thanks in advanced for help!