Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <locale.h>
- #include <conio.h>
- #include <iostream>
- using namespace std;
- int main()
- {
- char c;
- setlocale(LC_ALL, "Rus");
- char filePath[100];
- printf("ENTER SOURCE FILE: \n ");
- fgets(filePath, sizeof(filePath), stdin);
- FILE *fin = fopen(filePath, "r");
- if (!fin)
- {
- printf("\nERROR!!!\n");
- system("PAUSE");
- exit(EXIT_FAILURE);
- }
- FILE *fout = fopen("output.c", "w");
- c = fgetc(fin);
- while (c != EOF)
- {
- if ((c != '/') && (c != '\"') && (c != '\''))
- {
- fputc(c, fout);
- c = fgetc(fin);
- continue;
- }
- if ((c != '\"') && (c != '\''))
- {
- c = fgetc(fin);
- if (c == '/' || c == '*')
- {
- if (c == '/')
- {
- c = fgetc(fin);
- while ((c != '\n')&&(c != EOF)&&(c != '\r'))
- {
- if (c == '\\')
- {
- c = fgetc(fin);
- c = fgetc(fin);
- }
- else
- c = fgetc(fin);
- }
- continue;
- }
- c = fgetc(fin);
- while ((c)&&(c != EOF))
- {
- if (c == '*')
- {
- c = fgetc(fin);
- if (c == '/')
- {
- c = fgetc(fin);
- break;
- }
- }
- else
- c = fgetc(fin);
- }
- continue;
- }
- fputc('/', fout);
- continue;
- }
- if (c == '\"')
- {
- fputc(c, fout);
- c = fgetc(fin);
- while ((c != '\"') && (c != EOF))
- {
- if (c == '\\')
- {
- fputc(c, fout);
- c = fgetc(fin);
- fputc(c, fout);
- c = fgetc(fin);
- if (c == '\"') break;
- continue;
- }
- if (c == '\n' || c == '\r')
- break;
- fputc(c, fout);
- c = fgetc(fin);
- }
- fputc(c, fout);
- c = fgetc(fin);
- continue;
- }
- fputc(c, fout);
- c = fgetc(fin);
- while ((c != '\'') && (c != EOF))
- {
- if (c == '\\')
- {
- fputc(c, fout);
- c = fgetc(fin);
- if ((c != '\n')&&(c != '\r'))
- {
- fputc(c, fout);
- c = fgetc(fin);
- }
- }
- if (c == '\'')break;
- if ((c != '\n')&&(c!= '\r'))
- {
- fputc(c, fout);
- c = fgetc(fin);
- }
- else break;
- }
- fputc(c, fout);
- c = fgetc(fin);
- }
- printf("COMPLETE");
- fclose(fin);
- fclose(fout);
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement