/* write a manu driven program in 'c' which perform following
operation on string.
1)check one string is substring of another string
2)count the number of character in the string
3)exit */
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
void substr();
void count();
int choice;
clrscr();
while(1)
{
printf("\n1 :check substring");
printf("\n2 :count no. of occure ");
printf("\n3 :exit");
printf("\nenter your choice :");
scanf("%d",&choice);
switch(choice)
{
case 1:substr();
printf("\n\n");
getch();
break;
case 2:count();
printf("\n\n");
getch();
break;
case 3:exit();
}
}
}
void substr()
{
char str1[30],str2[30];
printf("\nenter one the string :");
flushall();
gets(str1);
printf("\nenter the second string :");
gets(str2);
if(strstr(str1,str2))
printf("\nthe given string is substring :");
else
printf("\nthe given string is not substring :");
}
void count()
{
char str[30],data;
int count=0,i,a;
printf("\nenter the string :");
flushall();
gets(str);
a=strlen(str);
printf("\nenter the character :");
scanf("%c",&data);
for(i=0;i<a;i++)
if(data==str[i])
count++;
printf("\ndata %c exist in the string %d times",data,count);
}
/*
1 :check substring
2 :count no. of occure
3 :exit
enter your choice :1
enter one the string :peer namaf
enter the second string :nadaf
the given string is not substring :
1 :check substring
2 :count no. of occure
3 :exit
enter your choice :1
enter one the string :peer nasa
enter the second string :nasa
the given string is substring :
1 :check substring
2 :count no. of occure
3 :exit
enter your choice :2
enter the string :peersaab nadaf
enter the character :a
data a exist in the string 4 times
1 :check substring
2 :count no. of occure
3 :exit
enter your choice :3
*/
No comments:
Post a Comment