Thread: Help with GetPrivateProfileSectionNames

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    5

    Help with GetPrivateProfileSectionNames

    I used GetPrivateProfileSectionNames to retrieve a list of the section names. The only problem is that I now have all the names stored into one char array seperated by \0s. What would be the best/easiest way to split the string up into individual char arrays. Also note that there won't be a set number of section names. Thanks for any help.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    IMHO, ini's have been made obsolete by the registry. So, it's been a long time since I've worked with ini's. But I believe the following code snippet may be helpful.

    Code:
    #define MAX 8192
    
    void ReadSections(char* IniPath)
    {
        LPTSTR lpszReturnBuffer;
        lpszReturnBuffer = new TCHAR[MAX];
        char* pNextSection = NULL;
           GetPrivateProfileSectionNames(lpszReturnBuffer,MAX,IniPath);
        pNextSection = lpszReturnBuffer;
        printf("%s\n", pNextSection);      
        while (*pNextSection != 0x00)
        {
            pNextSection = pNextSection + strlen(pNextSection) + 1;
            if(*pNextSection != 0x00)
            {
                printf("%s\n", pNextSection);
            }
        }
    }

Popular pages Recent additions subscribe to a feed