Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h> // qsort, toupper
- #include <string.h> // strlen
- #include <stdbool.h> // true
- #include <stdio.h> // puts, fflush, fgets
- #define BUF_SIZE 80
- int tovalid(int c)
- {
- c = toupper(c);
- if (c < 'Q' || c > 'Z') {
- c = 0;
- }
- return c;
- }
- void filter(char* dst, char* src)
- {
- int c;
- while (c = (unsigned char)*src++) {
- if (c = tovalid(c)) {
- *dst++ = c;
- }
- }
- *dst = '\0';
- }
- int charcmp(const void* a, const void* b)
- {
- int code_a = *(unsigned char*)a;
- int code_b = *(unsigned char*)b;
- return code_a - code_b;
- }
- int main(void)
- {
- char input[BUF_SIZE];
- char output[BUF_SIZE];
- bool Isbull = true;
- while (Isbull) {
- puts("Enter string:");
- fflush(stdin);
- fgets(input, sizeof(input), stdin);
- if (input[0] == '\n') { break; }
- filter(output, input);
- puts(output);
- qsort(output, strlen(output), sizeof(char), charcmp);
- puts(output);
- Isbull = false;
- }
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement