Originally Posted by
Salem
Personally, I would just use getline() to read each line in turn, then decide what to do about it.
Ok.. I tried this approach. Here's the code I'm coming up with:
Code:
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <string.h>
char* GetInfo(char* varname);
int main()
{
GetInfo("HP");
cout << "\n\n";
return(0);
}
char* GetInfo(char* varname)
{
char stream[256];
char* name;
int HP;
fstream file("test.txt", ios::in | ios::out | ios::nocreate | ios::noreplace);
file.getline(stream, 64);
file.getline(stream, 64, '|');
file.seekg(1, ios::cur);
file.getline(stream, 64);
name = stream;
cout << name;
file.getline(stream, 64, '|');
file.getline(stream, 64, '|');
HP = atol(stream);
cout << HP;
file.close();
return(stream);
}
So essentially, there's no way for me to be able to adjust to users making flatfiles in different formats? There's no way to do an if (strcmp(string, "HP")) { ... } setup, since that always fails. I can't make it not fail.
I mean, I can probally deal with arbitrary flatfiles, I'd just rather not have to program this interpertation code for every single flatfile type I have set up is all.
Thanks for the help, though.