Compiler Design: Program To Search A Character From A Given String
Compiler Design: Program To Search A Character From A Given String
#include<iostream.h>
#include<conio.h>
void main()
{
char a[20];
char b;
int l,i,j,k,flag=0;
cout<<"Enter the length of string:";
cin>>l;
cout<<"Enter the string:";
for(i=0;i<l;i++)
{
cin>>a[i];
}
cout<<"\nthe entered string is:";
for(j=0;j<l;j++)
{
cout<<a[j];
}
cout<<"\nEnter the character you want to search:";
cin>>b;
for(k=0;k<l;k++)
{
if(a[k]==b)
{
flag=1;
cout<<"index of "<<b<<" is:"<<k+1;
break;
}
}
if(flag==0)
{
cout<<"the character does not exist:\n";
}
getch();
}
OUTPUT:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#define MAX 50
struct node
{
char target[MAX] ;
char stack[MAX] ;
char *s, *t ;
int top ;
};
void main( )
{
struct node p ;
char expr[MAX] ;
initinfix ( &p ) ;
clrscr( ) ;
getch( ) ;
}
return -1 ;
}
else
{
char item = p -> stack[p -> top] ;
p -> top-- ;
return item ;
}
}
while ( *( p -> s ) )
{
if ( *( p -> s ) == ' ' || *( p -> s ) == '\t' )
{
p -> s++ ;
continue ;
}
if ( isdigit ( *( p -> s ) ) || isalpha ( *( p -> s ) ) )
{
while ( isdigit ( *( p -> s ) ) || isalpha ( *( p -> s ) ) )
{
*( p -> t ) = *( p -> s ) ;
p -> s++ ;
p -> t++ ;
}
}
if ( *( p -> s ) == '*' || *( p -> s ) == '+' || *( p -> s ) == '/' || *( p -> s ) == '%' || *( p -> s ) == '-' || *(
p -> s ) == '$' )
{
if ( p -> top != -1 )
{
opr = pop ( p ) ;
while ( priority ( opr ) >= priority ( *( p -> s ) ) )
{
*( p -> t ) = opr ;
p -> t++ ;
opr = pop ( p ) ;
}
push ( p, opr ) ;
push ( p, *( p -> s ) ) ;
}
else
push ( p, *( p -> s ) ) ;
p -> s++ ;
}
if ( *( p -> s ) == ')' )
{
opr = pop ( p ) ;
while ( ( opr ) != '(' )
{
*( p -> t ) = opr ;
p -> t++ ;
opr = pop ( p ) ;
}
p -> s++ ;
}
}
*( p -> t ) = '\0' ;
}
return 2 ;
break;
case '/':
return 2 ;
break;
case '%':
return 2 ;
break;
case '+':
return 1 ;
break;
case '-':
return 1 ;
break;
}
}
OUTPUT:
# include<stdio.h>
# include<conio.h>
# include<ctype.h>
typedef struct
{
int a[100];
int top;
}STACK;
void push(STACK *s,int x)
{
if(s->top==99)
printf("STACK OVERFLOW\n");
else
s->a[++s->top]=x;
}
s1.top=-1;
for(i=0;pos[i]!='\0';i++)
if(isdigit(pos[i]))
push(&s1,pos[i]-'0');/*use to find the integer value of it*/
else
{
p2=pop(&s1);
p1=pop(&s1);
result=operation(p1,p2,pos[i]);
push(&s1,result);
}/*end of for loop*/
return pop(&s1);
}
void main()
{
char postfix[100];
clrscr();
printf("Please Enter the VALID POSTFIX string\n\nOperands are SINGLE DIGIT\n\n");
gets(postfix);
printf("The Result is==>%d",evaluate(postfix));
getch();
}
OUTPUT:
#include<stdio.h>
#include<conio.h>
void main()
int x,y;
scanf("%d %d",&x,&y);
printf("x=%d \t y=%d",x,y);
interchange(x,y);
int z1;
z1=x1;
x1=y1;
y1=z1;
OUTPUT:
#include<iostream.h>
#include<conio.h>
void main()
int a, b;
swapref(a, b);
int temp;
temp = aa;
aa = bb;
bb = temp;
OUTPUT:
#include<iostream.h>
#include<conio.h>
void swapadd (int *, int *);
void main ()
{
int a, b ;
cout << "\nEnter two numbers = \n" ;
cin >> a >> b;
cout << "Before calling swapadd() function.";
cout << "\na = " << a;
cout << "\nb = " << b;
swapadd (&a, &b ) ;
cout << "\nAfter calling swapadd() function.";
cout << "\na = " << a;
cout << "\nb = " << b ;
}
OUTPUT: