[CODE] Bug in get_line

From: Andrey Fidrya (andrey@alex-ua.com)
Date: 10/15/00


Get_line ignores last line in file if it's not terminated with carriage
return...

int get_line(FILE * fl, char *buf)
{
  char temp[256];
  int lines = 0;

  do {
-    fgets(temp, 256, fl);
+    if (!fgets(temp, 256, fl)) // This also forces it to stop on errors
-    if (feof(fl))
      return (0);
    lines++;
  } while (*temp == '*' || *temp == '\n');

  temp[strlen(temp) - 1] = '\0';
  strcpy(buf, temp);
  return (lines);
}

Andrey


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 04/10/01 PDT