w3resource
C Programming Exercises

C Programming: Remove characters in String Except Alphabets

C String: Exercise-17 with Solution

Write a program in C to remove characters in String Except Alphabets.

C Programming: Remove characters in String Except Alphabets

Sample Solution:

C Code:

#include <stdio.h>
#include <string.h>
void main(){
    char str[150];
    int i,j;
	
       printf("\n\nRemove characters in String Except Alphabets :\n");
       printf("--------------------------------------------------\n");	

	printf("Input the string : ");
    fgets(str,sizeof str,stdin);	
    for(i=0; str[i]!='\0'; ++i)
    {
        while (!((str[i]>='a'&&str[i]<='z') || (str[i]>='A'&&str[i]<='Z' || str[i]=='\0')))
        {
            for(j=i;str[j]!='\0';++j)
            {
                str[j]=str[j+1];
            }
            str[j]='\0';
        }
    }
    printf("After removing the Output String : %s\n\n",str);
}

Sample Output:

Remove characters in String Except Alphabets :                                                                                
--------------------------------------------------                                                                            
Input the string : W3resource.com                                                                                             
After removing the Output String : Wresourcecom 

Flowchart :

Flowchart: Remove characters in String Except Alphabets

C Programming Code Editor:

Improve this sample solution and post your code through Disqus.

Previous: Write a program in C to find the number of times a given word 'the' appears in the given string.
Next: Write a program in C to Find the Frequency of Characters.

What is the difficulty level of this exercise?