Re: [NEWBIE][CODE] Files

From: Daniel A. Koepke (dkoepke@circlemud.org)
Date: 03/26/01


On Sun, 25 Mar 2001, Its Me Christian wrote:

>   FILE *ACLAN_FILE;
>    int num_lines = 0;
>    ACLAN_FILE=fopen("../lib/misc/clan", "r");
>   get_line(ACLAN_FILE, buf);
>   while (!feof(ACLAN_FILE))  {
>      num_lines++;
>      get_line(ACLAN_FILE,buf);
>   }
>   fclose(ACLAN_FILE);
>   ACLAN_FILE=fopen("../lib/misc/clan", "r");

Eww.  Do use rewind() rather than needlessly opening and closing files.
Do use proper error checking on opening files.  Do not use feof() and
get_line() together -- it's redundant, get_line() signals EOF.  Do not
count the number of lines in the file unless you really need it.


-dak

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/04/01 PST