home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / EDUCATIO / NTUMIN10.ZIP / CONVERT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-09  |  3.2 KB  |  110 lines

  1. /****************************************************************************
  2.  *
  3.  *    Program Name : CONVERT.C
  4.  *
  5.  *    This program converts output file generated by VAX C to a format
  6.  *    compatible with MS-DOS or PC-DOS.
  7.  *
  8.  * --------------------------------------------------------------------------
  9.  *    Copyright (c) 1992. All Rights Reserved. Nanyang Technological
  10.  *    University.
  11.  *
  12.  *    You are free to use, copy and distribute this software and its
  13.  *    documentation providing that:
  14.  *
  15.  *        NO FEE IS CHARGED FOR USE, COPYING OR DISTRIBUTION.
  16.  *
  17.  *        IT IS NOT MODIFIED IN ANY WAY.
  18.  *
  19.  *        THE COPYRIGHT NOTICE APPEAR IN ALL COPIES.
  20.  *
  21.  *    This program is provided "AS IS" without any warranty, expressed or
  22.  *    implied, including but not limited to fitness for any particular
  23.  *    purpose.
  24.  *
  25.  *    If you find NTUMIN fast, easy, and useful, a note or comment would be
  26.  *    appreciated. Please send to:
  27.  *
  28.  *        Boon-Tiong Tan or Othman Bin Ahmad
  29.  *        School of EEE
  30.  *        Nanyang Technological University
  31.  *        Nanyang Avenue
  32.  *        Singapore 2263
  33.  *        Republic of Singapore
  34.  *
  35.  ***************************************************************************/
  36.  
  37. #include <stdio.h>
  38. #include <string.h>
  39. #include <stdlib.h>
  40.  
  41. main()
  42.  
  43. {
  44.    unsigned char     *infile, *outfile;           /* filenames */
  45.         char     c, ans;
  46.    FILE              *in, *out;                   /* file pointers */
  47.  
  48.    printf("This program is for converting output files generated by VAX machine to\n");
  49.    printf("one compatible with MS-DOS or PC-DOS\n\n");
  50.    printf("Press any key to Continue or <ESC> to QUIT\n\n");
  51.    c = getch();
  52.    if (c==27)
  53.       exit(0);
  54.  
  55.    infile = (unsigned char *) malloc (21);      /* allocate space */
  56.    if (infile==0)
  57.       {
  58.      printf("Out of memory -- CONVERT, *infile\n");
  59.      printf("Program terminated - 1\n");
  60.      exit(0);
  61.       }
  62.  
  63.    outfile = (unsigned char *)malloc (21);      /* allocate space */
  64.    if (outfile==0)
  65.       {
  66.      printf("Out of memory -- CONVERT, *outfile\n");
  67.      printf("Program terminated - 2\n");
  68.      exit(0);
  69.       }
  70.  
  71.    printf("Enter input filename -> ");
  72.    gets(infile);                            /* read input filename */
  73.  
  74.    printf("Enter output filename -> ");
  75.    gets(outfile);                           /* read output filename */
  76.  
  77.    printf("Please hang on, doing conversion ... \n\n");
  78.  
  79.    if ((in = fopen(infile, "r+")) == NULL)             /* open 1st file */
  80.       {
  81.      printf("Error opening file, %s\n", infile);
  82.      printf("Program terminated - 3\n");
  83.      exit(0);
  84.       }
  85.  
  86.    if ((out = fopen(outfile, "w+")) == NULL)           /* open 2nd file */
  87.       {
  88.      printf("Error opening file, %s\n", outfile);
  89.      printf("Program terminated - 4\n");
  90.      exit(0);
  91.       }
  92.  
  93.    while ((c=fgetc(in)) != EOF)                /* get char from infile */
  94.      {
  95.         if (c=='J')                        /* treat 'J' as CR */
  96.            fprintf(out, "\n");
  97.         else
  98.            fprintf(out, "%c", c);          /* put char to outfile */
  99.      }
  100.  
  101.    free(infile);                               /* free pointers */
  102.    free(outfile);
  103.  
  104.    fclose(in);                                 /* close files */
  105.    fclose(out);
  106.  
  107.    printf("Conversion Completed.\n");
  108. }
  109.  
  110.