Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- int main(void)
- {
- int sym, c = 0, rev = 0;
- FILE* file;
- FILE* fout;
- if ((file = fopen("input.txt", "rt")) == NULL) {
- printf("Can't open input file!\n");
- return -1;
- }
- if ((fout = fopen("output.txt", "wt")) == NULL) {
- printf("Can't open output file!\n");
- fclose(file);
- return -1;
- }
- sym = fgetc(file);
- if (sym == EOF)
- {
- printf("cannot read text\n");
- fclose(file);
- fclose(fout);
- return -1;
- }
- while(sym != EOF)
- {
- if (sym == '\\'){
- rev = 1;
- }
- else if (sym == 'n' && rev == 1)
- {
- fprintf(fout, "\n");
- c = 0;
- rev = 0;
- }
- else if (sym == ' ' || sym == '\t')
- {
- c++;
- }
- else if (c != 0)
- {
- if (fputc('-', fout) == EOF)
- {
- printf("Cannot write the symbol\n");
- return -1;
- }
- if (fputc(sym, fout) == EOF)
- {
- printf("Cannot write the symbol\n");
- return -1;
- }
- c = 0;
- }
- else
- {
- if (fputc(sym, fout) == EOF)
- {
- printf("Cannot write the symbol\n");
- return -1;
- }
- }
- sym = fgetc(file);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement