/* Write a program to perform verious string operations such as copy,length,compare,reverse,substring,pallindrome and concatenation and to find occurrence substring etc.,with and without using library functions */
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int opt,l1,l2;
char str1[20],str2[20],*p;
clrscr();
printf("\n********************************************************************************\n\t1.Copy \n\t2.Length \n\t3.Compare \n\t4.Reverse \n\t5.Concatenation \n\t6.Substring \n\t7.Pallindrome \n\t8.Exit\n \n********************************************************************************\n");
printf("\n\tSelect the option :");
scanf("%d",&opt);
printf("\n\tEnter string1 :");
scanf("%s",str1);
printf("\n\tEnter string2 :");
scanf("%s",str2);
printf("\n\tstring1 is %s,",str1);
printf("\n\tstring2 is %s,",str2);
switch(opt)
{
case 1:strcpy(str2,str1);
printf("\n\tstring1 is %s,",str1);
printf("\n\tstring2 is %s,",str2);
break;
case 2:l1=strlen(str1);
l2=strlen(str2);
printf("\n\tLength of string1 is %d",l1);
printf("\n\tLength of string2 is %d",l2);
break;
case 3:l1=strcmp(str1,str2);
if(l1==0)
printf("\n\tThe strings are equal");
else
printf("\n\tThe strings are not equal");
break;
case 4: strrev(str1);
printf("\n\tReversed string1 is %s",str1);
break;
case 5: strcat(str1,str2);
printf("\n\tConcatenated string is %s",str1);
printf("\n\tString 2 is %s",str2);
break;
case 6:p=strstr(str1,str2);
if(p==NULL)
printf("String2 is not substring of string1");
else
printf("\n\tString2 is substring of string1");
break;
case 7:
strcpy(str2,str1);
strrev(str2);
l1=strcmp(str1,str2);
if(l1==0)
printf("String1 is pallindrom");
else
printf("String1 is not pallindrom");
break;
case 8: exit();
break;
default:printf("\n\tInvalid switch option");
}
getch();
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int opt,l1,l2;
char str1[20],str2[20],*p;
clrscr();
printf("\n********************************************************************************\n\t1.Copy \n\t2.Length \n\t3.Compare \n\t4.Reverse \n\t5.Concatenation \n\t6.Substring \n\t7.Pallindrome \n\t8.Exit\n \n********************************************************************************\n");
printf("\n\tSelect the option :");
scanf("%d",&opt);
printf("\n\tEnter string1 :");
scanf("%s",str1);
printf("\n\tEnter string2 :");
scanf("%s",str2);
printf("\n\tstring1 is %s,",str1);
printf("\n\tstring2 is %s,",str2);
switch(opt)
{
case 1:strcpy(str2,str1);
printf("\n\tstring1 is %s,",str1);
printf("\n\tstring2 is %s,",str2);
break;
case 2:l1=strlen(str1);
l2=strlen(str2);
printf("\n\tLength of string1 is %d",l1);
printf("\n\tLength of string2 is %d",l2);
break;
case 3:l1=strcmp(str1,str2);
if(l1==0)
printf("\n\tThe strings are equal");
else
printf("\n\tThe strings are not equal");
break;
case 4: strrev(str1);
printf("\n\tReversed string1 is %s",str1);
break;
case 5: strcat(str1,str2);
printf("\n\tConcatenated string is %s",str1);
printf("\n\tString 2 is %s",str2);
break;
case 6:p=strstr(str1,str2);
if(p==NULL)
printf("String2 is not substring of string1");
else
printf("\n\tString2 is substring of string1");
break;
case 7:
strcpy(str2,str1);
strrev(str2);
l1=strcmp(str1,str2);
if(l1==0)
printf("String1 is pallindrom");
else
printf("String1 is not pallindrom");
break;
case 8: exit();
break;
default:printf("\n\tInvalid switch option");
}
getch();
}
future software debugger..
ReplyDelete