I've been playing Valve games for quite some time, but I've never been good at using char arrays for string management. I REALLY would like to improve, given how much time I spend on them. Obviously, using the correct lines would be nice, but since all SDK functions return char * or accept it as args, it does not do much to convert the fourth as well. Does anyone have any good links, how much do they better understand them? Most of what I find on Google just were snippets.
Also, I am trying to parse a very simple text file. The main content is as follows:
PatchVersion = 1.1.1.2 ProductName = l4d APPID = 440
I want to get PatchVersion and ProductName. My code looks something like this, but really just the lack of proper knowledge left me in a dead end. strtok only retrieves the token before the '=' sign, strchr gives me a pointer to its location, but just doesn't know a good method.
bool ParseSteamFile()
{
FileHandle_t file;
file = filesystem->Open("steam.inf", "r", "MOD");
if(file)
{
int size = filesystem->Size(file);
char *line = new char[size + 1];
while(!filesystem->EndOfFile(file))
{
char *subLine = filesystem->ReadLine(line, size, file);
Msg("SUBLINE: %s\n", subLine);
char *buffer = "";
if(strstr(subLine, "PatchVersion"))
{
char *c = strtok(subLine, "=");
while(c != NULL)
{
Msg("Token: %s\n", c);
c = strtok(subLine, "=");
}
}
}
}
}
source
share