#include
#include
void main()
{
int no,m,ch ,i,j,n,k,flag=0;
char str[20],str2[20],str3[20],str4[20];
char wish;
clrscr();
do
{
menu:
printf(“\n1.length of the string.”);
printf(“\n2.copying string another.”);
printf(“\n3.concatination of two string”);
printf(“\n4.reversing the string”);
printf(“\n5.checking palindrome or not.”);
printf(“\n6.checking sub-string in the string.” );
printf(“\nEnter the choice:”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
printf(“Enter the string: “);
flushall();
gets(str);
for(i=1;str[i]!=’\0′;i++); //to find the length of the string
printf(“the length of the string is:%d “,i);
break;
case 2:
printf(“Enter the string: “);
flushall();
gets(str);
for(i=0;str[i]!=’\0′;i++)//TO COPY A STRING IN OTHER
{
str2[i]=str[i];
}
str2[i]=’\0′;
printf(“\n the copied string is: “);
puts(str2);
break;
case 3:
printf(“Enter the string: “);
flushall();
gets(str);
printf(“\n Enter the second string”);
flushall();
gets(str2);
i=0;
while(str[i]!=’\0′)
i++;
for(j=0;str2[j]!=’\0′;j++,i++)//TO CONCATINATE TWO STRING
str[i]=str2[j];
str[i]=’\0′;
printf(“\nthe concatinated string is: “);
puts(str);
break;
case 4:
printf(“Enter the string: “);
flushall();
gets(str);
i=0;
while(str[i]!=’\0′)
i++;
i–;
for(j=0;str[j]!=’\0′,i>=0;j++,i–)//TO REVERSE STRING
str2[j]=str[i];
str2[j]=’\0′;
printf(“\n the reverse string is: “);
puts(str2);
break;
case 5:
printf(“Enter the string: “);
flushall();
gets(str);
i=0;
while(str[i]!=’\0′)
i++;
i–;
flag=1;
for(j=0;i>j;j++,i–)
{
if(str[i]!=str[j])
{
flag=0;
break;
}
}
if(flag==1)
printf(“\nthe string is palindrom.”);
else
printf(“\nthe string is not palindrom.”);
break;
case 6:
printf(“Enter the string: “);
flushall();
gets(str);
printf(“\nEnter the second string: “); //TO FIND WETHER SUBSTRING EXISTS OR NOT
gets(str4);
for(m=0;str[m]!=’\0′;m++);
for(k=0;k<=m-1;k++)
{
for(j=0;str4[j]!=’\0′;j++)
{
if(str[k+j]!=str4[j])
{
flag=0;
break;
}
}
if(str4[j]==’\0′)
{
flag=1;break;}
}
if(flag==1)
printf(“\nsubstring found at position:%d “,j+k);
else
printf(“\n substring donot exists”);
break;
default:
printf(“\n wrong choice!!!!”);
break;
}
printf(“\nwant to continue(y/n)”);
scanf(“%c”,&wish);
}
while(wish!=’n’);
getch();
}
Leave a Reply