Guest User

get-columns

a guest
Apr 17th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <ctype.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.     if(isatty(fileno(stdin))){
  8.         return 1;
  9.     }
  10.    
  11.     int i=0, space_count=0, skip_print=0, empty_cols=6;
  12.     char pipe[65536];
  13.     while((pipe[++i] = getchar()) != EOF);
  14.    
  15.     for(int j=0; j<i; ++j){
  16.         if(pipe[j] == '\n'){
  17.             while(empty_cols > 0){
  18.                 printf("\"\",");
  19.                 --empty_cols;
  20.             }
  21.             space_count=0;
  22.             empty_cols=6;
  23.             continue;
  24.         }
  25.        
  26.         if(pipe[j] == ' '){
  27.             ++space_count;
  28.             continue;
  29.         }
  30.        
  31.         if(skip_print > 0){
  32.             --skip_print;
  33.             continue;
  34.         }
  35.        
  36.         if(pipe[j] == 'O' && pipe[j+1] == 'i'){
  37.             skip_print=2;
  38.             continue;
  39.         }
  40.        
  41.         if(pipe[j] == 'B' && pipe[j+1] == 'r'){
  42.             skip_print=4;
  43.             continue;
  44.         }
  45.        
  46.         if(pipe[j] == 'O' && pipe[j+1] == 't'){
  47.             skip_print=4;
  48.             continue;
  49.         }
  50.        
  51.         while(space_count > 18){
  52.             printf("\"\",");
  53.             space_count -= 18;
  54.             --empty_cols;
  55.         }
  56.        
  57.         space_count=0;
  58.        
  59.         if(pipe[j-1] == ' '){
  60.             printf("\"");
  61.         }
  62.        
  63.         if(isdigit(pipe[j]) || pipe[j] == '.'){
  64.             putchar(pipe[j]);
  65.             if(pipe[j+1] == ' ' || pipe[j+1] == '\n'){
  66.                 printf("\",");
  67.                 --empty_cols;
  68.             }
  69.         }
  70.         else{
  71.             if((pipe[j] == 'G' || pipe[j] == 'g') && pipe[j+1] == 'a' && pipe[j+2] == 'l'){
  72.                 printf("gallons\",");
  73.                 skip_print=6;
  74.                 --empty_cols;
  75.             }
  76.             else if((pipe[j] == 'B' || pipe[j] == 'b') && pipe[j+1] == 'a' && pipe[j+2] == 'r'){
  77.                 printf("barrels\",");
  78.                 skip_print=6;
  79.                 --empty_cols;
  80.             }
  81.         }
  82.     }
  83.    
  84.     return 0;
  85. }
Add Comment
Please, Sign In to add comment