home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / 04stdlib / notes1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  943 b   |  43 lines

  1. /*
  2.  *    notes1 -- add an entry to a "notes" text file
  3.  *
  4.  *    version 1: appends new data to NOTES.TXT in the
  5.  *    current directory -- uses local date/time stamp
  6.  *    as a header for each new entry
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <time.h>
  12. #include <local\std.h>
  13.  
  14. main()
  15. {
  16.     FILE *fp;
  17.     static char notesfile[MAXPATH + 1] = { "notes.txt" };
  18.     char ch;
  19.     long ltime;
  20.     static char pgm[MAXNAME + 1] = { "notes1" };
  21.  
  22.     extern void fatal(char *, char *, int);
  23.  
  24.     /* try to open notes file in current directory */
  25.     if ((fp = fopen(notesfile, "a")) == NULL)
  26.         fatal(pgm, notesfile, 1);
  27.  
  28.     /* append a header and date/time tag */
  29.     ltime = time(NULL);
  30.     fprintf(stderr, "Appending to %s: %s",
  31.          notesfile, ctime(<ime));
  32.     fprintf(fp, "%s", ctime(<ime));
  33.  
  34.     /* append new text */
  35.     while ((ch = getchar()) != EOF)
  36.         putc(ch, fp);
  37.  
  38.     /* clean up */
  39.     if (fclose(fp))
  40.         fatal(pgm, notesfile, 2);
  41.     exit(0);
  42. }
  43.