C Programming Code Examples C > Strings Code Examples Program to Remove all Characters in a String Except Alphabet Program to Remove all Characters in a String Except Alphabet This program takes a string from the user and stored in the variable line. The, within the for loop, each character in the string is checked if it's an alphabet or not. If any character inside a string is not a alphabet, all characters after it including the null character is shifted by 1 position to the left. #include<stdio.h> int main() { char line[150]; int x, j; printf("Enter a string: "); gets(line); for(x = 0; line[x] != '\0'; ++x) { while (!( (line[x] >= 'a' && line[x] <= 'z') || (line[x] >= 'A' && line[x] <= 'Z') || line[x] == '\0') ) { for(j = x; line[j] != '\0'; ++j) { line[j] = line[j+1]; } line[j] = '\0'; } } printf("Output String: "); puts(line); return 0; }