Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.85 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. //int main(int argc, char *argv[]) {
  4. int main() {
  5.     FILE *fp;
  6.  
  7.     fp = fopen("/home/eddie/CLionProjects/ps5/input.txt", "r");
  8. //    fp = fopen(argv[1], "r");
  9.  
  10.     int other = 0;
  11.     char c = (char) fgetc(fp);
  12.  
  13.     char input[1000];
  14.     unsigned int nInput = 0;
  15.     char output[1000];
  16.     unsigned int n = 0;
  17.  
  18.     for (int i = 0; i < 50; i++) {
  19.         output[i] = '\0';
  20.     }
  21.  
  22.     while (c != EOF) {
  23.         if (c == 'S') {
  24.             c = (char) fgetc(fp);
  25.  
  26.             if (c == 'T') {
  27.                 c = (char) fgetc(fp);
  28.  
  29.                 if (c == 'A') {
  30.                     c = (char) fgetc(fp);
  31.  
  32.                     if (c == 'R') {
  33.                         c = (char) fgetc(fp);
  34.  
  35.                         if (c == 'T') {
  36.                             c = (char) fgetc(fp);
  37.                             c = (char) fgetc(fp);
  38.  
  39.                             while (c != EOF) {
  40.                                 input[nInput] = c;
  41.                                 nInput++;
  42.                                 c = (char) fgetc(fp);
  43.                             }
  44.  
  45.                             for (int i = 0; i < nInput; i++) {
  46.                                 printf("%c", input[i]);
  47.                             }
  48.  
  49.                             nInput = 0;
  50.  
  51.                             while (input[nInput] != 'S' && input[nInput+1] != 'T' && input[nInput+2] != 'O' && input[nInput+3] != 'P') {
  52.                                 if (other == 0) {
  53.                                     if (input[nInput] == ' ') {
  54.                                         other = 1;
  55.                                     }
  56.  
  57.                                     nInput++;
  58.                                 } else {
  59.                                     if (input[nInput] == ' ') {
  60.                                         other = 0;
  61. //                                        printf("%c", c);
  62.                                         output[n] = input[nInput];
  63.                                         n++;
  64.                                         nInput++;
  65.                                     } else {
  66. //                                        printf("%c", c);
  67.                                         output[n] = input[nInput];
  68.                                         n++;
  69.                                         nInput++;
  70.                                     }
  71.                                 }
  72.                             }
  73.                         }
  74.                     }
  75.                 }
  76.             }
  77.         } else {
  78.             c = (char) fgetc(fp);
  79.         }
  80.     }
  81.  
  82.     fclose(fp);
  83.  
  84.     fp = fopen("/home/eddie/CLionProjects/ps5/output.txt", "w");
  85. //    fp = fopen(argv[2], "w");
  86.  
  87.     n = 0;
  88.  
  89.     while (output[n+1] != '\0') {
  90. //        printf("%c", output[n]);
  91.         fputc(output[n], fp);
  92.         n++;
  93.     }
  94.  
  95.     fclose(fp);
  96.  
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement