home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / network / netlib_1 / NetLibSrc / c / readline < prev    next >
Text File  |  1995-01-10  |  637b  |  39 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include "socketlib.h"
  6.  
  7. /*
  8.  * Read a line from a file, junking comments
  9.  */
  10. char *__socketlib_readline(FILE *file)
  11. {
  12.   static char line[256];
  13.  
  14.   char *hash;
  15.  
  16.   do
  17.   {
  18.     /* Read a line from the file */
  19.     if (fgets(line, 256, file) == NULL)
  20.       return NULL;
  21.  
  22.     /* Format the line */
  23.     if ((hash = strchr(line, '#')) != NULL)
  24.     {
  25.       /* Throw away any comments on the line */
  26.       *hash = '\0';
  27.     }
  28.     else
  29.     {
  30.       /* Remove the newline */
  31.       line[strlen(line) - 1] = '\0';
  32.     }
  33.   }
  34.   while (strlen(line) == 0);
  35.  
  36.   /* Return the line */
  37.   return line;
  38. }
  39.