Q) Write a C program to remove the characters in String except alphabets.
Sol)
#include<stdio.h>
int main()
{
char line[150];
int i,j;
printf("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("Output String is : ")
puts(line);
return 0;
}
:: OUTPUT ::
Enter a string: G-="o";][d
Output String is: God
Sol)
#include<stdio.h>
int main()
{
char line[150];
int i,j;
printf("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("Output String is : ")
puts(line);
return 0;
}
:: OUTPUT ::
Enter a string: G-="o";][d
Output String is: God
#include
ReplyDelete#include
int main()
{
char a[1000],b[1000];
int i,j,l;
printf("Enter a string:\n");
gets(a);
for(i=0,j=0;a[i]!='\0';i++){
if('a'<=a[i]&&'z'>=a[i]||'A'<=a[i]&&'Z'>=a[i]||a[i]==' '){
b[j]=a[i];
j++;
}
}
b[j]='\0';
puts(b);
return 0;
}
#include
ReplyDelete#include
#include
#include
int main()
{
int i,len;
char stri[40];
printf("\nEnter the String\n");
gets(stri);
len=strlen(stri);
for(i=0;i<len;i++)
{
if(!isalpha(stri[i]))
stri[i]='\0';
if(stri[i]=='\0')
continue;
else
printf("%c",stri[i]);
}
getch();
}