Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define MAX_SIZE 100
  5.  
  6. char* cleanText(char* text) {
  7.     int size = 0;
  8.     int newSize = 0;
  9.     char c;
  10.     char* output;
  11.  
  12.     for(int i = 0; i < MAX_SIZE; i++) {
  13.         c = *(text + i);
  14.         if(c == '\0') {
  15.             break;
  16.         }
  17.         if((c >= 65 && c <= 90) || (c >= 97 && c <= 122)) {
  18.             size++;
  19.         }
  20.     }
  21.  
  22.     output = (char*) malloc(sizeof(char) * (size + 1));
  23.  
  24.     for(int i = 0; i < MAX_SIZE; i++) {
  25.         c = *(text + i);
  26.         if(c == '\0') {
  27.             break;
  28.         }
  29.         if((c >= 65 && c <= 90) || (c >= 97 && c <= 122)) {
  30.             *(output + newSize++) = c;
  31.         }
  32.     }
  33.     *(output + size) = '\0';
  34.  
  35.     return output;
  36. }
  37.  
  38. int main() {
  39.     char input[MAX_SIZE];
  40.     char* clean;
  41.  
  42.     scanf("%s", input);
  43.     clean = cleanText(input);
  44.     printf("%s", clean);
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement