Advertisement
sheefoo

comment.cpp

May 30th, 2020
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <locale.h>
  4. #include <conio.h>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     char c;
  12.     setlocale(LC_ALL, "Rus");
  13.  
  14.     char filePath[100];
  15.     printf("ENTER SOURCE FILE: \n  ");
  16.     fgets(filePath, sizeof(filePath), stdin);
  17.    
  18.     FILE *fin = fopen(filePath, "r");
  19.     if (!fin)
  20.     {
  21.         printf("\nERROR!!!\n");
  22.         system("PAUSE");
  23.         exit(EXIT_FAILURE);
  24.     }
  25.  
  26.     FILE *fout = fopen("output.c", "w");
  27.  
  28.     c = fgetc(fin);
  29.  
  30.     while (c != EOF)
  31.     {
  32.         if ((c != '/') && (c != '\"') && (c != '\''))
  33.         {
  34.             fputc(c, fout);
  35.             c = fgetc(fin);
  36.             continue;
  37.         }
  38.        
  39.         if ((c != '\"') && (c != '\''))
  40.         {
  41.             c = fgetc(fin);
  42.             if (c == '/' || c == '*')
  43.             {
  44.                 if (c == '/')
  45.                 {
  46.                     c = fgetc(fin);
  47.                     while ((c != '\n')&&(c != EOF)&&(c != '\r'))
  48.                     {
  49.                         if (c == '\\')
  50.                         {
  51.                             c = fgetc(fin);
  52.                             c = fgetc(fin);
  53.                         }
  54.                         else
  55.                             c = fgetc(fin);
  56.                     }
  57.  
  58.                     continue;
  59.                 }
  60.  
  61.                 c = fgetc(fin);
  62.                 while ((c)&&(c != EOF))
  63.                 {
  64.  
  65.                     if (c == '*')
  66.                     {
  67.                         c = fgetc(fin);
  68.                         if (c == '/')
  69.                         {
  70.                             c = fgetc(fin);
  71.                             break;
  72.                         }
  73.                     }
  74.                     else
  75.                         c = fgetc(fin);
  76.                 }
  77.  
  78.                 continue;
  79.             }
  80.  
  81.             fputc('/', fout);
  82.             continue;
  83.         }
  84.  
  85.         if (c == '\"')
  86.         {
  87.             fputc(c, fout);
  88.             c = fgetc(fin);
  89.             while ((c != '\"') && (c != EOF))
  90.             {
  91.                 if (c == '\\')
  92.                 {
  93.                     fputc(c, fout);
  94.                     c = fgetc(fin);
  95.                     fputc(c, fout);
  96.                     c = fgetc(fin);
  97.  
  98.                     if (c == '\"') break;
  99.  
  100.                     continue;
  101.                 }
  102.  
  103.                 if (c == '\n' || c == '\r')
  104.                     break;
  105.            
  106.                 fputc(c, fout);
  107.                 c = fgetc(fin);
  108.             }
  109.            
  110.             fputc(c, fout);
  111.             c = fgetc(fin);
  112.  
  113.             continue;
  114.         }
  115.  
  116.         fputc(c, fout);
  117.         c = fgetc(fin);
  118.         while ((c != '\'') && (c != EOF))
  119.         {
  120.             if (c == '\\')
  121.             {
  122.                 fputc(c, fout);
  123.                 c = fgetc(fin);
  124.                 if ((c != '\n')&&(c != '\r'))
  125.                 {
  126.                     fputc(c, fout);
  127.                     c = fgetc(fin);
  128.                 }
  129.  
  130.             }
  131.             if (c == '\'')break;
  132.             if ((c != '\n')&&(c!= '\r'))
  133.             {
  134.                 fputc(c, fout);
  135.                 c = fgetc(fin);
  136.             }
  137.  
  138.             else break;
  139.         }
  140.         fputc(c, fout);
  141.         c = fgetc(fin);
  142.        
  143.     }
  144.  
  145.     printf("COMPLETE");
  146.     fclose(fin);
  147.     fclose(fout);
  148.     system("PAUSE");
  149.     return 0;
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement