Xref: utzoo comp.lang.c:40019 comp.unix.aix:5711 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!tahoe!bally!siva From: siva@bally.Bally.COM (Siva Chelliah) Newsgroups: comp.lang.c,comp.unix.aix Subject: when to fflush ? Keywords: fflush , fseek, fwrite Message-ID: <504@bally.Bally.COM> Date: 13 Jun 91 15:51:36 GMT Distribution: usa Organization: Bally systems Lines: 36 Hi, I have a question. Does seeking to the end of a file causes a flushing of the buffer ? In my opinion it should not. Look at the following program. Even though I write only 5 bytes, when you do a cat on test.out , you see "hello." Move the sleep(500) before fseek , and you won't see it. It happened on both IBM RT running AIX 2.1 and RS 6000 running AIX 3.1. Please comment. Thanks , Siva ------------------------------- #include main () { FILE *fp; char buf[80]; strcpy(buf,"hello\n"); system ("touch test.out"); /* just to create the file */ fp = fopen ("test.out","r+"); fseek(fp,0L,0); /* seek to start of file - you do not need this */ fwrite(buf,strlen(buf),1,fp); fseek(fp,0L,2); /* seek to end of file */ sleep(500); fclose (fp); } -- /=*=*=*=*=*=*=*=*=*=*=*=*=*=*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\ | Siva@bally.bally.com | He who asks is a fool for five minuites,| | Bally Systems, | but he who does not ask remains a fool | | Reno, NV 89502 | forever -Old Chinese saying |