Menu BAR

FEEL FREE TO ASK ANY PROGRAM and please mention any error if you find it

17 Oct 2013

C Program to remove all characters except string

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