Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* The app reads text from stdin -- the text is two columns of words
- * separated by tab characters -- removes the first column and the tab
- * characters, splits the remaining text into single letters, removes
- * duplicates and capitalizez the letters. The result is written to
- * stdout.*/
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <ctype.h>
- int main()
- {
- char *input_buffer;
- (void)scanf("%m[a-z\t\n]", &input_buffer);
- char *output_buffer;
- size_t input_buffer_size = strlen(input_buffer);
- output_buffer = malloc(input_buffer_size);
- int input_buffer_index = 0;
- int copy_flag = 0;
- int output_buffer_index = 0;
- while (input_buffer[input_buffer_index] != '\0') {
- if (input_buffer[input_buffer_index] == '\t') copy_flag = 1;
- if (input_buffer[input_buffer_index] == '\n') copy_flag = 0;
- if (copy_flag != 0 && input_buffer[input_buffer_index] != '\t')
- {
- output_buffer[output_buffer_index] = input_buffer[input_buffer_index];
- output_buffer_index++;
- }
- input_buffer_index++;
- }
- output_buffer[output_buffer_index] = '\0';
- size_t output_buffer_size = strlen(output_buffer);
- size_t i, j;
- for (i = 0; i < output_buffer_size; ++i)
- {
- for (j = i + 1; j < output_buffer_size; ++j)
- {
- if (output_buffer[j] == output_buffer[i]) output_buffer[j] = '\0';
- }
- }
- for (i = output_buffer_size; i > 0; --i)
- {
- if (output_buffer[i - 1] != '\0') printf("%c\n", toupper(output_buffer[i - 1]));
- }
- free(output_buffer);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement