🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #7136

Re: FILE Problem

#7136
From: Wiljo
Date: Mon, 07 Mar 2005 12:00
39 lines
2252 bytes
Marco wrote:

> This is an example of my code:
> 
>   FILE *file = fopen (".\\Cfg\\CompCod.dat", "w"); 
I also concur that you shouldn't use relative paths, unless you are absolutely 
sure what the current directory is. But when your program is moved to another 
directory in the future, your program might fail again!
>  .....
>                                                    
>   for (int i=0; i<FLista.Count(); i++)             
>     fprintf (file, "%d=%s\n",FLista[i]);           
>                                                    
Here is another mistake, or probably a typo. The fprintf statement contains the 
format "%d=%s\n", specifying two additional arguments (one for %d and one for 
%s). Only the latter one is given.

Another suggestion for the file reader:

 > while (!feof(file))
 >    {
 >    fgets(szBuff, 120, FMsgFile);
 >    FLista[i] = szBuff;
 >    i++;
 >    }

You can replace this by

   while( fgets( szBuff, 120, FMsgFile ))
   {
     FLista[i] = szBuff;
     ++i;
   }

The fgets function can be used to test for eof.
Or, because FLista is a string list, why don't you use the LoadFromFile member 
function of the string list component itself?

Wiljo.
Technical Details
Message-ID: <422c425d$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <422c284b$1@newsgroups.borland.com> <422c2ce5@newsgroups.borland.com> <422c3529$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,dd88f23059572aae
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Mon, 07 Mar 2005 13:00:01 +0100
From: Wiljo <invalid@invalid.address>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040616
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: FILE Problem
References: <422c284b$1@newsgroups.borland.com> <422c2ce5@newsgroups.borland.com> <422c3529$1@newsgroups.borland.com>
In-Reply-To: <422c3529$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 81.207.96.249
Message-ID: <422c425d$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1110196829 81.207.96.249 (7 Mar 2005 04:00:29 -0800)
Lines: 39
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail