Advertisement
Guest User

K&R C 1-23

a guest
Mar 17th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. #define TEST_STR "You're cunt 1/0 == inf /**/ //hui"
  5.  
  6. #define ARR_SIZE(x) (sizeof(x)/sizeof(x[0]))
  7.  
  8. int main(int argc, char** argv) {
  9.     // K&R C 2nd edition task #1-23
  10.     // Has been tested on its own source code
  11.     // Govno ebat'
  12.     /*
  13.      *
  14.      *
  15.      * Hui blyad
  16.      */
  17.     FILE *inp;
  18.     FILE *outp;
  19.     inp = fopen("input.c", "r");
  20.     outp = fopen("output.c", "w");
  21.     int symbol;
  22.     long long pos;
  23.  
  24.     bool single_quote = false;
  25.     bool double_quote = false;
  26.  
  27.     while ((symbol = fgetc(inp)) != EOF) {
  28.         switch (symbol) {
  29.             case '"':
  30.                 if (!single_quote)
  31.                     double_quote = !double_quote;
  32.                 fputc(symbol, outp);
  33.                 break;
  34.             case '\'':
  35.                 if (!double_quote)
  36.                     single_quote = !single_quote;
  37.                 fputc(symbol, outp);
  38.                 break;
  39.             case '/':
  40.                 fgetpos(inp, &pos);
  41.                 printf("%d %d at pos %lld\n", single_quote, double_quote, pos);
  42.                 if (!(single_quote || double_quote)) {
  43.                     symbol = fgetc(inp);
  44.                     if (symbol == '/') {
  45.                         while (fgetc(inp) != '\n');
  46.                     }
  47.                     else if (symbol == '*') {
  48.                         while ((symbol = fgetc(inp)) != EOF) {
  49.                             if (symbol == '*') {
  50.                                 if (fgetc(inp) == '/') {
  51.                                     break;
  52.                                 }
  53.                             }
  54.                         }
  55.                     }
  56.                     else {
  57.                         fputc('/', outp);
  58.                         fputc(symbol, outp);
  59.                     }
  60.                 }
  61.                 else {
  62.                     fputc(symbol, outp);
  63.                 }
  64.                 break;
  65.             default:
  66.                 fputc(symbol, outp);
  67.                 break;
  68.         }
  69.     }
  70.     fclose(inp);
  71.     fclose(outp);
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement