C Programming
Computer Programming

C program to Remove all characters in a string except alphabets



Write a program in C to Remove all characters in a string except alphabets

\* C program to Remove all characters in a string except alphabets *\

# include < stdio.h >
# include < conio.h >
int   main( )
{

char line[150] ;
int i, j ;
printf("\n Enter a string: ") ;
gets(line) ;
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("\n Output String: ") ;
puts(line) ;
return 0 ;

}

Output of Program :

Output of C program to Remove all characters in a string except alphabets