program
name:- write a menu driven prodram in 'c' which performs the following
,operations on string . write separate function for each option,
-cheak if one string is
substring of another string ,
-count number of occurrences of
acharacter in the string,
-Exit.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void
main()
{
int
ch;
char
str1[30],str2[30],occ;
int
i=0,cnt=0;
clrscr();
while(1)
{
printf("\n
menues");
printf("\n1.
check if one string is substring of another string");
printf("\n2.
count number of occurrences of characters in the string");
printf("\n3.exit");
printf("\nEnter
Your choice: ");
scanf("%d",&ch);
switch(ch)
{
case
1:printf("\n enter the first string");
scanf("%s",str1);
printf("\n enter the second string");
scanf("%s",str2);
if(strstr(str1,str2)==NULL)
{
printf("\n second string is not substring of first
string");
}
else
{
printf("\n second string is substring of first string");
}
break;
case
2:
printf("\n enter
the string");
scanf("%s",&str1);
printf("\n enter the character
to find occurences");
scanf("%s",&occ);
i=0,cnt=0;
while(str1[i]!='\0')
{
if(str1[i]==occ)
{
cnt++;
}
i++;
}
printf("\n the number of occurencs is %d",cnt);
break;
case
3:exit(0);
}
}
getch();
}
/*output
menues
1. check if one
string is substring of another string
2. count number
of occurrences of characters in the string
3.exit
Enter Your
choice: 1
enter the first stringindia
enter the second
stringind
second string is substring of first string
menues
1. check if one
string is substring of another string
2. count number
of occurrences of characters in the string
3.exit
Enter Your
choice: 2
enter the stringmaharashtra
enter the character to find occurencesa
the number of occurencs is 4
menues
1. check if one
string is substring of another string
2. count number
of occurrences of characters in the string
3.exit */