.c code: fileInfo.c


This program reads the records from a file and writes some notes bout what it read.
 

#include 

#define MAXRECSIZE (32768)
#ifndef TRUE
#define TRUE (1 == 1)
#endif
#ifndef FALSE
#define FALSE (!(TRUE))
#endif

int mystrlen(char *str) {
  int idx = 0;
  while (*(str + idx) != 0) {
    ++idx;
  }
  return idx;
}

void processFile1(FILE *inp, FILE *out) {
  int maxreclen = 0;
  int minreclen = MAXRECSIZE;
  int numrec = 0;
  int reclen = 0;
  char irec[MAXRECSIZE];
  while ((char *)NULL != fgets(irec, sizeof(irec)-1, inp)) {
    reclen = mystrlen(irec);
    ++numrec;
    if (reclen > maxreclen) { maxreclen = reclen; }
    if (reclen < minreclen) { minreclen = reclen; }
  }
  fprintf(out, "record count %d.\n", numrec);  
  fprintf(out, "max record Length %d.\n", maxreclen);
  fprintf(out, "min record Length %d.\n", minreclen);

}

int main(int argcnt, char **argval, char **env) {
  fprintf(stderr, "Processing stdin to stdout\n");
  processFile1(stdin, stdout);
  fprintf(stderr, "Finished processing.\n");
}