6.26.2010

LEADING TRAILING

#include
#include
#include
#include
char t[30][10][10],lset[30];
int h;
void leading(char ter[],char nonter[],char sym)
{
char *str;
int post,posnont;
str=strchr(nonter,sym);
posnont=str-nonter;
for(int i=0;i<10;i++)
{

if(t[posnont][i][0]!='\0')
{
if(strchr(ter,t[posnont][i][0])!=NULL)
{
str=strchr(ter,t[posnont][i][0]);
post=str-ter;
lset[post]=t[posnont][i][0];

}
else if(strchr(nonter,t[posnont][i][0])!=NULL && t[posnont][i][1]!='\0')
{
str=strchr(ter,t[posnont][i][1]);
post=str-ter;
lset[post]=t[posnont][i][1];
if(t[posnont][i][0]!=sym)
leading(ter,nonter,t[posnont][i][0]);

}
else
{
leading(ter,nonter,t[posnont][i][0]);
}
}
}
return;
}

void main()
{
clrscr();
char ter[30],nonter[30],temp[30];
int i=0,j=0;
fstream fp;
fp.open("grammer.txt",ios::in);
fp>>ter;
fp>>nonter;
fp>>temp;
do
{
j=0;
while(strcmp(temp,"$")!=0)
{
strcpy(t[i][j],temp);
fp>>temp;
j++;
}
i++;
fp>>temp;
}while(fp.eof()!=1);
fp.close();
char sym;
cout<<"Enter symbol: ";
cin>>sym;
leading(ter,nonter,sym);
j=0;
cout<<"\n\n";
while(j<10)
{
if(strchr(ter,lset[j])!=NULL)
{
cout< }
j++;
}
getch();
return;
}

No comments: