home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / XBBS7200.ZIP / XBBS7200.TAR / allign / fallign.c < prev   
Encoding:
C/C++ Source or Header  |  1991-01-11  |  1.1 KB  |  49 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <sys/locking.h>
  4. main()
  5. {
  6.     FILE           *inbuf, *outbuf;
  7.     int             code;
  8.     int             count;
  9.     char            infile[99], outfile[99];
  10.     int            datar;
  11.     int        fds;
  12.     printf("\nInput the old user file name: ");
  13.     scanf("%s", infile);
  14.     printf("\n");
  15.     strcpy(outfile, infile);
  16.     strcat(outfile, ".OLD");
  17.     (void) unlink(outfile);
  18.     (void) link(infile, outfile);
  19.     (void) unlink(infile);
  20.     if ((inbuf = fopen(outfile, "r")) == NULL) {
  21.         printf("\n\rError opening old users file.\n\r");
  22.         exit(1);
  23.     }
  24.     if ((outbuf = fopen(infile, "a+")) == NULL) {
  25.         printf("\n\rError opening new users file.\n\r");
  26.         exit(1);
  27.     }
  28.     fds = fileno(outbuf);
  29.     rewind(outbuf);
  30.     locking(fds, LK_LOCK, 0L);
  31.     while ((datar = fgetc(inbuf)) != EOF) {
  32.         if (datar == '~')
  33.             {
  34.             datar = fgetc(inbuf);
  35.             if( datar == ' ') datar = '\n';
  36.             putc('~', outbuf);
  37.             }
  38.         putc(datar, outbuf);
  39.     }
  40.     fclose(inbuf);
  41.     fclose(outbuf);
  42.     strcpy(outfile, "chmod 660 ");
  43.     strcat(outfile, infile);
  44.     (void) system(outfile);
  45.     strcpy(outfile, "chown bbs ");
  46.     strcat(outfile, infile);
  47.     (void) system(outfile);
  48. }
  49.