Computing.Net > Forums > Programming > C++ and INI Files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C++ and INI Files

Reply to Message Icon

Name: jeff800000
Date: January 11, 2005 at 13:32:11 Pacific
OS: WinXP
CPU/Ram: 1.7
Comment:

I need a simple way to Write and Read from an INI files. I'm having trouble reading the section headdings E.G; [section1]. How would i b able to go to a section then read a vale E.G: value1=1 (so i want to read "1"). I've found some classes that say they make it quite easy but could not get them to work.

I have done some looking around and have found the GetPrivateProfileString may be able to read values.

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: geddi
Date: January 13, 2005 at 14:37:00 Pacific
Reply:

Why not just read the file and scan it in memory;
Something like

HANDLE hFile CreateFile (blabla, OPEN_EXISTING, blabla);
DWORD Size=GetFileSize(hFile);
BYTE* Buf=(BYTE*)VirtualAlloc(blabla,Size,blabla);
ReadFile(blabla, Buf, Size, blabla);
int l=0;
while ((l<Size)&(lstrcmpi(Buf+l,"[section]")) l++;
l+=lstrlen("[section]");

while ((l<Size)&(lstrcmpi(Buf+l,"value1=")) l++;
l+=lstrlen("value1=");

int l2=l

while ((l2<Size)&(lstrcmpi(Buf+l2,"\r\n")) l2++;
Buf[l2]=0;
char Result[512];
lstrcpy(Result,Buf+l);


Geddi


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C++ and INI Files

C++, INI Files www.computing.net/answers/programming/c-ini-files/12013.html

Reading and writing INI files (BATCH) www.computing.net/answers/programming/reading-and-writing-ini-files-batch/18930.html

INI Files in C. Read and Write www.computing.net/answers/programming/ini-files-in-c-read-and-write/19339.html