Advertisement
banovski

Unltracolumnizer

Sep 12th, 2024 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.69 KB | Source Code | 0 0
  1. /* The app reads text from stdin -- the text is two columns of words
  2.  * separated by tab characters -- removes the first column and the tab
  3.  * characters, splits the remaining text into single letters, removes
  4.  * duplicates and capitalizez the letters. The result is written to
  5.  * stdout.*/
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <stdlib.h>
  10. #include <ctype.h>
  11.  
  12. int main()
  13. {
  14.      char *input_buffer;
  15.      (void)scanf("%m[a-z\t\n]", &input_buffer);
  16.      char *output_buffer;
  17.      size_t input_buffer_size = strlen(input_buffer);
  18.      output_buffer = malloc(input_buffer_size);
  19.      int input_buffer_index = 0;
  20.      int copy_flag = 0;
  21.      int output_buffer_index = 0;
  22.      while (input_buffer[input_buffer_index] != '\0') {
  23.           if (input_buffer[input_buffer_index] == '\t') copy_flag = 1;
  24.           if (input_buffer[input_buffer_index] == '\n') copy_flag = 0;
  25.           if (copy_flag != 0 && input_buffer[input_buffer_index] != '\t')
  26.           {
  27.                output_buffer[output_buffer_index] = input_buffer[input_buffer_index];
  28.                output_buffer_index++;
  29.           }
  30.           input_buffer_index++;
  31.      }
  32.      output_buffer[output_buffer_index] = '\0';
  33.  
  34.      size_t output_buffer_size = strlen(output_buffer);
  35.  
  36.      size_t i, j;
  37.      for (i = 0; i < output_buffer_size; ++i)
  38.      {
  39.           for (j = i + 1; j < output_buffer_size; ++j)
  40.           {
  41.                if (output_buffer[j] == output_buffer[i]) output_buffer[j] = '\0';
  42.           }
  43.      }
  44.  
  45.      for (i = output_buffer_size; i > 0; --i)
  46.      {
  47.           if (output_buffer[i - 1] != '\0') printf("%c\n", toupper(output_buffer[i - 1]));
  48.      }
  49.  
  50.      free(output_buffer);
  51.      return(0);
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement