|
|
Antoher way to do it, "the old fashion way".
bool ReadKonfig()
{
char lineBuf[300];
int i;
FILE * fil;
if((fil = fopen("C:\\TheFile.ini", "rt")) == NULL) {
// Couldn't open the file
return false;
}
// The file is open, read it.
while(fgets(lineBuf, sizeof(lineBuf), fil) != NULL) {
// We have a line
// Remove trailing crlf's.
for(i = strlen(lineBuf) - 1; i >= 0; i--) {
if(lineBuf[i] == '\r' || lineBuf[i] == '\n') lineBuf[i] = '\0';
}
// Ignore comments.
// The line is considdered a comment if the line starts with a ';', '#', space, tab or is empty.
if(lineBuf[0] == ';' || lineBuf[0] == '#' || lineBuf[0] == ' ' || lineBuf[0] == '\t'
|| !strlen(lineBuf)) continue;
// It's a real line, process it.
// ...
}
fclose(fil);
return true;
}
|
|
|
|
|
Thank you, but it still seems that the while loop gets endless for some reason, not sure why.
With best regards,
RedDragon2kx
|
|
|
|
|
Hello.
The while loop reads line after line from the text file. When the last line has been read, fgets returns NULL and the while-loop breaks.
The original code (from which I copied the code) works just fine.
Are you sure your infile is a pure text-file? If you read it in Notepad, does it look OK?
Try the code with another text file. Create one i Notepad and try it out.
The code should work OK, assuming it's a normal ANSI-textfile. The code doesn't work for Unicode files, though. Do you think that could be the problem?
|
|
|
|
|
Hello,
I could fix the problem. It was a problem with the CString object because I used += and the String was getting to large or something like this. I'm now using just = and everything works fine
With best regards,
Benedikt
|
|
|
|
|
Great!
Good luck with the rest of your program.
Kakan
|
|
|
|
|
I have created a MFC program. I have selected that Visual Studio should prioritize size when I build it in release. This makes the size of the exe-file 18kb. BUT it still uses 4Mb of RAM when it's run. I don't use any big resources/data types/variables. Is there any way to minimize the amount of RAM the program uses or is it MFCs fault?
|
|
|
|
|
Where did you come up with it uses 4 MB RAM?
I bet it might use 4 MB of 'virtual memory' but what is the program's working set size? That is how much 'real' RAM it might be using at any time. The rest of it is sitting off in the paging file, so who would care?
|
|
|
|
|
Well, I used the most obvious way - Ctrl+Alt+Del (taskmanager).
|
|
|
|
|
See here.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Oh, I see! Thanks, now I'm not worried anymore!
|
|
|
|
|
Any quick function or class to get the IP address of the PC the program runs on ?
Thanks,
Shay
|
|
|
|
|
One way is to call gethostname() followed by gethostbyname() .
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
|
Does this code look reasonable ?
I did get my PC name on the netwrok but not actual IP address
<br />
char * hostname=new char[50];<br />
gethostname (hostname,50);<br />
<br />
hostent *host_info=new hostent;<br />
host_info=gethostbyname(hostname);<br />
char FAR** iplist=host_info->h_addr_list;<br />
char *ip=iplist[0];
|
|
|
|
|
char hostname[51] = { 0 };
gethostname(hostname, 50); will save you one delete[].
hostent* host_info = gethostbyname(hostname) will save you one memory leak.
char* ip = host_info->h_addr will save you some typing.
A better code snippet:
char hostname[51] = { 0 };
gethostname(hostname, 50);
hostent* host_info = gethostbyname(hostname);
char* ip = host_info->h_addr;
Good music: In my rosary[^]
|
|
|
|
|
Agreed, this is a nicer and cleaner code.
However, I still don't get the actual IP adress I want, all I get is what we call the "Connection-specific DNS Suffix" and not the actual numbers....
any help is good.
Shay
|
|
|
|
|
Shay Harel wrote:
all I get is what we call the "Connection-specific DNS Suffix" and not the actual numbers....
check [GetNetworkParams ] api is of any help?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
ThatsAlok wrote:
check [GetNetworkParams] api is of any help?
Which member of the FIXED_INFO structure are you referring to?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
DavidCrow wrote:
Which member of the FIXED_INFO structure are you referring to?
Sorry I got confused
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
You know what, I found that in the MSDN help, but I have one problem with it.
I need to include the Iphlpapi.h and my code will not link when I do that.
The web site say:Library -> Link to Iphlpapi.lib.
Where do I add this DLL to my code ?
Shay
|
|
|
|
|
Shay Harel wrote:
The web site say:Library -> Link to Iphlpapi.lib.
you Need PSDK for that, search MSDN.microsoft.com for that
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
The only things that comes up is the Windows server 2003 PSDK and I don't know if I should load this one.
Do you have any specific link ?
Thanks again in advance...
|
|
|
|
|
If you are using VC++ v6, you will need to request the Platform SDK on CD. It is no longer available for download.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Working with a CDHtmlDialog...almost every 3rd or 4th time I display the dialog the dialog just does not display. It's intermittent and when I step through the code I can't catch what is causing it. InitDialog does not get called when it fails.
Similar to this problem I found here.[^].
Any ideas or suggestions?
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|