C Program to remove all the characters from a String except Alphabets


 

// Program by Akash Tripathi (@proakash256)
  
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
    char *s;
    s = malloc(1024 * sizeof(char));
    scanf("%[^\n]"s);
    s = realloc(sstrlen(s) + 1);
    char *s1;
    s1 = malloc(1024 * sizeof(char));
    int j = 0;
    for(int i = 0i < strlen(s); i = i + 1)
    {
        if((s[i]>= 'a' && s[i] <= 'z') ||
            (s[i]>= 'A' && s[i] <= 'Z'))
        {
            s1[j] = s[i];
            j = j + 1;
        }
    }
    s1[j] = '\0';
    s1 = realloc(s1 , (j + 1));
    printf("The Processed String is : ");
    puts(s1);
    free(s);
    free(s1);
    return 0;
}

Comments