All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
listio.h File Reference
#include <stdio.h>
#include "oldlist.h"

Go to the source code of this file.

Functions

LIST read_list (const char *filename)
 

Function Documentation

LIST read_list ( const char *  filename)

Definition at line 45 of file listio.cpp.

45  {
46  FILE *infile;
47  char s[CHARS_PER_LINE];
48  LIST list;
49 
50  if ((infile = open_file (filename, "r")) == NULL)
51  return (NIL_LIST);
52 
53  list = NIL_LIST;
54  while (fgets (s, CHARS_PER_LINE, infile) != NULL) {
55  s[CHARS_PER_LINE - 1] = '\0';
56  if (strlen (s) > 0) {
57  if (s[strlen (s) - 1] == '\n')
58  s[strlen (s) - 1] = '\0';
59  if (strlen (s) > 0) {
60  list = push (list, (LIST) strsave (s));
61  }
62  }
63  }
64 
65  fclose(infile);
66  return (reverse_d (list));
67 }
LIST reverse_d(LIST list)
Definition: oldlist.cpp:371
#define NIL_LIST
Definition: oldlist.h:126
#define strsave(s)
Definition: cutil.h:111
FILE * open_file(const char *filename, const char *mode)
Definition: cutil.cpp:82
#define CHARS_PER_LINE
Definition: cutil.h:57
#define NULL
Definition: host.h:144
LIST push(LIST list, void *element)
Definition: oldlist.cpp:323