Mail Archives: djgpp/2003/05/21/19:09:03
Subject: | File I/O question
|
Date: | Wed, 21 May 2003 19:14:34 -0400
|
MIME-Version: | 1.0
|
Message-ID: | <795DD3C2E97585449DCDEEE79CCD5C22BB5D@email2k.compuweigh.com>
|
X-MS-Has-Attach: | |
X-MIMEOLE: | Produced By Microsoft Exchange V6.0.6249.0
|
X-MS-TNEF-Correlator: | |
content-class: | urn:content-classes:message
|
Thread-Topic: | File I/O question
|
Thread-Index: | AcMf7r0W2NMg7hS1T12/aR7+hw6hIQ==
|
From: | "Alex O" <Alex AT compuweigh DOT com>
|
To: | "DJGPP (E-mail)" <djgpp AT delorie DOT com>
|
X-MIME-Autoconverted: | from quoted-printable to 8bit by delorie.com id h4LN8np04850
|
Hi everybody,
Can somebody explain me what is wrong with the following code snippet?
The reason I am asking is because the original file WATTCP.CFG never gets changed!
As you can see, I tried two different functions to write data to the file and each one of those returned the correct number of characters written,
but when I go to view the file it is not even touched (even the file date is not changed). How come?
BTW, does fgets() move the file pointer as it advances?
...
if( (ptr = fopen("wattcp.cfg", "r+")) != NULL )
{
while( fgets(tmp_buf, 99, ptr) )
{
//Skip the comment lines
if( tmp_buf[0] != '#' )
{
if( !strncmp(tmp_buf, "my_ip = ", 8) )
{
_inet_ntoa((CHAR *)ip_buf, nonvol->IP_Addr);
n = fprintf(ptr, "my_ip = %s ; mandatory\n", ip_buf);
}
else if( !strncmp(tmp_buf, "netmask = ", 10) != NULL )
{
_inet_ntoa((CHAR *)ip_buf, nonvol->Subnet_Mask);
sprintf(tmp_buf, "netmask = %s ; mandatory if not using DHCP\n", ip_buf);
n = fwrite(tmp_buf, sizeof(BYTE), strlen(tmp_buf), ptr);
}
}
}
fclose(ptr);
}
...
Thanks for any good advice how to make this thing work.
Regards,
Alex Oleynikov
- Raw text -