home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / GLOB.ZIP / EXAMPLE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-07-20  |  717 b   |  37 lines

  1. /* Example program demonstrating the use of glob() */
  2.  
  3. #include "glob.h"
  4.  
  5.  main() {
  6.      char **names;
  7.      names = glob("*.?");
  8.      if (names) {
  9.         printf("expansion of *.? is:\n");
  10.          print(names);
  11.      } else
  12.          printf("glob() error number %d (see glob.h)\n",globerror);
  13.         recover(names);
  14.  }
  15.  
  16.  recover(names)        /* free() all the space used up by **names; */
  17.  char **names;
  18.  {
  19.      int i = 0;
  20.      while (names[i] != (char *)0) {
  21.      free(names[i]);
  22.      i++;
  23.      }
  24.      free(names);
  25.  }
  26.  
  27.  print(names)        /* print out all the filenames returned by glob() */
  28.  char **names;
  29.  {
  30.      int i;
  31.      i = 0;
  32.      while (names[i] != (char *)0) {
  33.      printf("%s\n",names[i]);
  34.      i++;
  35.      }
  36.  }
  37.