Wednesday, February 19, 2014

C Program to Perform String Manipulation Using Built in Function

with 0 Comment
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[20],str2[20];
int l,s,y,ch;
clrscr();
do
{
printf("\n Menu\n");
printf("\n 1.Concatenation\n");
printf("\n 2.Length\n");
printf("\n 3.Copy\n");
printf("\n 4.Comparison\n");
printf("\n 5.Reverse\n");
printf("\n 6.Exit\n");
printf("\n Enter our choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\n Concatenation of the String\n");
printf("\n************************************\n");
printf("\n Enter the String1\n");
scanf("%s",str1);
printf("\n Enter the String2\n");
scanf("%s",str2);
strcat(str1,str2);
printf("\n Concatenation is: %s",str1);
break;
}
case 2:
{
printf("\n Length of the String\n");
printf("\n****************************\n");
printf("\n Enter the String\n");
scanf("%d",str1);
l=strlen(str1);
printf("\n Length of the String is: %d",l);
break;
}

case 3:
{
printf("\n Copy the String\n");
printf("\n**************************\n");
printf("\n Enter the String1 \n");
scanf("%s",str2);
strcpy(str1,str2);
printf("\n Original String: %s",str2);
printf("\n Copied String:%s",str1);
break;
}

case 4:
{
printf("\n Comparision of the String \n");
printf("\n **********************************\n");
printf("\n Enter the String1 \n");
scanf("%s",str1);
printf("\n Enter the String2 \n");
scanf("%s",str2);
s=strcmp(str1,str2);
if(s==0)
{
printf("\n The Given Strings are Equal \n");
}
else
{
printf("\n The Given Strings are not Equal\n");
}
break;
}

case 5:
{
printf("\n Reverse the String\n");
printf("\n ********************************\n");
printf("\n Enter the String\n");
scanf("%s",str1);
strrev(str1);
printf("Reverse the String is: %s",str1);
break;
}

case 6:
exit();
break;
}
printf("\n Do you want to continue(0/1) \n");
scanf("%d",&y);
}
while(y!=0);
getch();
}

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive