Remove all characters in a string except alphabet
C program to remove all characters in a string except alphabet.
Program
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define MAX 50
void main()
{
char str[MAX];
int i, j, len;
printf("Enter the string\t:");
gets(str);
len = strlen(str);
for(i=0;i<len;i++)
{
if(!((str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z')))
{
for(j=i;j<len;j++)
{
str[j] = str[j+1];
}
len = len-1;
i--;
}
}
str[len] = '\0';
printf("\nModified string\t:%s",str);
getch();
}
Output
Enter the string :co23u'r;'sec\]rux
Modified string :coursecrux