/* * File: * testreadline.c * Author: * Samuel A. Rebelsky * Version: * 1.0 of March 2003 * Summary: * A quick test of the readLine procedure. */ /********************************************************************* * Headers * ***********/ #include #include #include "readline.h" /********************************************************************* * Constants * *************/ #define STRLEN 10 /********************************************************************* * Main * ********/ int main(int argc, char *argv[]) { char ch; char str[STRLEN]; FILE *infile; int result; if (argc == 1) { infile = stdin; } else { infile = fopen(argv[1], "r"); if (infile == NULL) { fprintf(stderr, "Invalid file: %s\n", argv[1]); exit(EXIT_FAILURE); } /* if (infile == NULL) */ } /* if (argc > 1) */ while ((ch = fgetc(infile)) != EOF) { ungetc(ch, infile); if (readLine(infile, str, STRLEN)) printf("[%s]\n", str); else printf("[%s]", str); } /* while */ if (argc > 1) fclose(infile); exit(EXIT_SUCCESS); } /* main */