Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: Deletion of text inside brackets : C Code

Sunday, December 16, 2012

Deletion of text inside brackets : C Code


C program to read a string and remove anything written inside closed brackets '(' ,')':

#include<stdio.h>
int main()
{
char s[200],temp;
int l,i=0,flag=1,j;
printf("\n Enter the string:");
do
      {
       s[i]=getchar();
       }
       while(s[i++]!='\n');
       s[i]='\0';
       i=0;
       while(s[i]!='\0')
       {

        if(s[i]=='(')
                  {
                  while(s[i]!=')')
                  ++i;
                  }
     if(s[i]!=')')   
        printf("%c",s[i]);
     i++;
        }
      return 0;
}
INPUT/OUTPUT:
Enter the string:amhjdg (dshjg)(dbh)hjdv dgfv (a)
OUTPUT: amhjdg hjdv dgfv

No comments:

Post a Comment