From: "Florian X" Newsgroups: comp.os.msdos.djgpp References: <38b2ab5f$0$83570 AT SSP1NO17 DOT highway DOT telekom DOT at> <38B2BD38 DOT 4134FA71 AT ma DOT tum DOT de> Subject: Re: File Date: Tue, 22 Feb 2000 18:41:19 +0100 X-Newsreader: Microsoft Outlook Express 4.71.1712.3 X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3 Lines: 53 Message-ID: <38b2c9cb$0$30920@SSP1NO17.highway.telekom.at> NNTP-Posting-Host: 212.183.97.19 X-Trace: newsreader.vienna.highway.telekom.at 951241163 30920 212.183.97.19 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Now I know why f == 0: It cannot be opened: perror prints PERMISSION DINIED! Thanks!! Waldemar Schultz schrieb in Nachricht <38B2BD38 DOT 4134FA71 AT ma DOT tum DOT de>... >Florian X schrieb: >> >> Hi! >> >> I use this in my program: >> >> char *string= "Hello world"; >> FILE * f = fopen("file.txt", "a"); >> fprintf(f, "%-128s", string); >> >> // ftell(f); >> >> fclose(f); >> >> But it doesn't write the text to the file, if i use ftell(...) after >> fopen(...), ftell(...) returns -1 (error); >> >> ftell > >I tried this with gcc and it works as expected. > >======================================= >#include > >int main(void) >{ >char *string= "Hello world"; >FILE * f = fopen("file.txt", "a"); > > if(!f) > { > perror("file.txt"); > return 1; > } > fprintf(f, "%-128s\n", string); > > printf("%ld\n",ftell(f)); > > fclose(f); > > return 0; >} >======================================= >Try this standalone. May be you currupted your system elsewhere >and now you stare at the wrong place. hope that helps.