Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3322808
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:13:37+00:00 2026-05-17T23:13:37+00:00

I have been modding Valve games for quite a while, but one that I

  • 0

I have been modding Valve games for quite a while, but one that I have never been good at in the least is using the char arrays to manipulate strings. I would REALLY like to improve considering how much time I waste on them. Obviously using proper Strings would be nice, but since all of the SDK functions return char *, or take it as args, it doesn’t make much since to convert back and fourth. Does anyone have any good links as far as understanding them better? Most of what I find on Google has just been snippets.

Also, I am trying to parse a very simple text file. Basically the contents look like this…

PatchVersion=1.1.1.2
ProductName=l4d
appID=440

I want to get the PatchVersion and ProductName. My code looks something like this, but really just make lack of proper knowledge has left me stumped. strtok only retrieves the token prior to the ‘=’ sign, strchr gives me a pointer to the location of it, but just don’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, "=");
                }
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:13:37+00:00Added an answer on May 17, 2026 at 11:13 pm

    There’s nothing wrong with using C-strings. It will however require you to write quite a bit of very low-level code, which has already been abstracted away when using String objects.

    In general, a C-String is just an array of bytes (each byte corresponding to the ascii value of a character) with a null byte at the end. The actual syntax of the commands however can be a little esoteric, I recommended cplusplus.com as a reference.

    Your second call to strtok needs to be called with null, rather than the subLine again:

          char *c = strtok(subLine, "=");
            while(c != NULL)
            {
                Msg("Token: %s\n", c);
                c = strtok(null, "=");
            }
    

    At the moment you are tokenizing by the equals sign, so you will end up with:

    PatchVersion
    =1.1.1.2 ProductName
    =l4d appID
    =440
    

    Don’t forget that strtok consumes the input string, so subLine will be empty once your loop finishes.

    I would begin by tokenizing the string by spaces to get each key-value pair. Then I would split each key-value pair into it’s constituent elements and store the needed ones. The (s)scanf function can do this type of parsing very well. To read one pair into name and value:

    char * name = new char[255];
    char * value = new char[255];
    sscanf(subLine, "%s=%s", name, value);
    

    You may then use strncpy to copy the value into the appropriate location. sscanf does not consume the input, so subsequent calls will have to move the pointer of subLine to beyond the previous match (or use three %s=%s pairs in the format expression, along with three name and value variable pairs, if you know there will always be three).

    The important thing is to get your application code as far away from the low level operations as is reasonable. If you do this type of manipulation often, finding or creating a library which parses files such as this might be a good (and fun) idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have been using CruiseControl for quite a while with NUnit and NAnt. For
Have been playing around with linq but there is one thing I cant seem
Have been using it for a while with CodeIgniter and I can't remember if
Have been looking at the MVC storefront and see that IQueryable is returned from
Have been studying the file system related classes of Adobe AIR 1.5, but so
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
I have been using PHP and JavaScript for building my dad's website. He wants
I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,
Have been programming with VS studio 2005/2008 making ASP.NET applications for a while. I
Have been struggling with Javascript closure for a while trying to wrap brain around

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.