Mail Archives: djgpp/1999/07/31/13:05:07
Thank you for your answers, both of them fix the problem.
Pavlos
Davin McCall wrote in message
<37a15d60 DOT 24986840 AT newsserver DOT cc DOT monash DOT edu DOT au>...
>Inserting "fflush(f)" immediately after the "fwrite" line solves the
>problem. <SNIP>
>Davin.
>
fred smith wrote in message ...
>If you add:
>fseek (f, 0L, SEEK_CUR);
>immediately before the ftruncate it works fine.
>Fred
>On Thu, 29 Jul 1999 06:18:21 +0300, "Pavlos" <trash24379 AT usa DOT net>
>wrote:
>
>>Hello,
>>I know that most of 'bug' reports are actually a fault of the user... Do I
>>do something wrong here?
>>
>>This simple program will truncate the file only if you comment out #define
>>BUGGY.
>>At least in my PC...
>>If you don't comment #define BUGGY, it won't truncate the file.
>>Here is the code.
>>When you run it, press '1' the first time to create the file. Then run it
>>again and press '2' to truncate it.
>>Thank you.
>>
>>Pavlos
>>
>><--- cut here --->
>>
>>#include <stdio.h>
>>#include <stdlib.h>
>>
>>#define BUGGY
>>
>>int main(int argc, char **argv)
>>{
>> FILE *f;
>> char buf[1000];
>>
>> printf("1: Create file (1000 bytes), 2:Truncate file (to 500)\n");
>> printf("Your choice: ");
>>
>> switch(getch())
>> {
>> case '1':
>> f = fopen("TEST1234.$$$", "wb+");
>> fwrite(buf, 1000, 1, f);
>> return(0);
>>
>> case '2':
>> f = fopen("TEST1234.$$$", "rb+");
>> fread(buf, 1000, 1, f);
>> #ifdef BUGGY
>> fseek(f, 500, SEEK_SET);
>> fwrite(buf, 500, 1, f);
>> #endif
>> ftruncate(fileno(f), 500);
>> return(0);
>>
>> default:
>> return(0);
>> }
>>}
>>
>><--- cut here --->
>>
- Raw text -