Advertisement
banovski

Lines: numbering, replacing tabs with arrows

May 24th, 2024 (edited)
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | Source Code | 0 0
  1. /* The utility reads text from stdin and prepends each line with a
  2.  * number. If a line contains a tab character, the tab character gets
  3.  * replaced with an arrow character. */
  4.  
  5. #include <stdio.h>
  6.  
  7. #define MAX_BUFF_SIZE 65536
  8.  
  9. int main()
  10. {
  11.      char buffer[MAX_BUFF_SIZE] = {};
  12.      char *buff_ptr;
  13.      int number = 1;
  14.      int counter = 0;
  15.  
  16.      buff_ptr = fgets(buffer, MAX_BUFF_SIZE - 1, stdin);
  17.      while(buff_ptr)
  18.      {
  19.           printf("%d. ", number);
  20.           while(buffer[counter] != 0)
  21.           {
  22.                if(buffer[counter] == '\t')
  23.                     printf("Β β†’ ");
  24.                else
  25.                     (void) putc(buffer[counter], stdout);
  26.  
  27.                counter += 1;
  28.           }
  29.           counter = 0;
  30.           buff_ptr = fgets(buffer, MAX_BUFF_SIZE - 1, stdin);
  31.           number += 1;
  32.      }
  33.  
  34.      return(0);
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement