C Program to Remove all Characters in a String Except Alphabet



 c program to remove all characters in a string except alphabet

Learn C - C tutorial - c program to remove all characters in a string except alphabet - C examples - C programs

C Program to Remove all Characters in a String Except Alphabet

  • This program takes strings from user and removes all characters in that string except alphabets.Then we use for loop until all characters of string is checked.
  • If any character inside a string is not an alphabet, it removed.

Sample Code

#include<stdio.h>
int main()
{
    char line[150]="wi4k5i.te78ch90y";
    ut
    int i, j;
    printf("string:wi4k5i.te78ch90y\n ");
    for(i=0; line[i]!='\0'; ++i)
    {
        while (!( (line[i] > = 'a' && line[i] <= 'z') || (line[i] > = 'A' && line[i] <= 'Z') || line[i] == '\0') )
        {
            for(j=i; line[j]!='\0'; ++j)
            {
                line[j] = line[j+1];
            }
            line[j] = '\0';
        }
    }
    printf("Output String: ");
    puts(line);
    return 0;
}

Output

string:wi4k5i.te78ch90y
 Output String: wikitechy


View More Quick Examples


Related Searches to C Program to Remove all Characters in a String Except Alphabet