/*
  Poor man's cat --- display the contents of one file

  Usage:  pmcat filename

  MAT 4970
  Bill Slough
  February 7, 2012
*/

#include <stdio.h>

int main(int argc, char *argv[]) {
    if (argc != 2) {
	/* Exactly two command-line arguments are expected; complain and quit. */
	fprintf(stderr, "Usage: %s filename\n", argv[0]);
	return 1;
    }
    else {
	/* Is the provided filename really a file? */
	FILE *in = fopen(argv[1], "r");
	if (in == NULL) {
	    fprintf(stderr, "%s: %s: Could not open.\n", argv[0], argv[1]);
	    return 2;
	}
	else {
	    /* OK; everything looks good ---
	       process the file character by character */
	    int ch;
	    while ((ch = fgetc(in)) != EOF) {
		printf("%c", ch);
	    }
	    fclose(in);
	    return 0;
	}
    }
}
