Home »
Code Examples »
C Code Examples
C – Remove characters in string except alphabet Code Example
The code for Remove characters in string except alphabet
#include<stdio.h>
int main()
{
char str1[256],str2[256];
int i, j;
printf("Enter a string: ");
fgets(str1, sizeof(str1), stdin);
for(i=0,j=0;str1[i]!='\0';i++)
{
if((str1[i]>='A' && str1[i]<='Z')||(str1[i]>='a' && str1[i]<='z'))
{
str2[j]=str1[i];
j++;
}
}
str2[j]='\0';
printf("Result: %s",str2);
return 0;
}
/*
Output:
Enter a string: Ihelp@123!Hello, World!
Result: IhelpHelloWorld
*/
Code by IncludeHelp,
on August 04, 2022