/*-------------------------------------------------------------------------------------------------
program
: Write a program in c to carry out following operation on
strings using library functions
a.
To concatenate a string s2 to string s1.
b.
To find the lengh of given string.
c.
To compare two string s1 and s2.
d.
To copy a string s2 to another string s2.
Crated By : JABIR DAUD PATHAN
Branch
: COMPUTER ENGINEERING
------------------------------------------------------------------------------------------------*/
//---------------------- Header Files
--------------------------------
#include<stdio.h>
#include<conio.h>
#include<string.h>
//--------------------- Main Function
--------------------------------
void
main()
{
char str1[20],str2[20],str3[20]; //Variable declaration
int ch;
clrscr();
//Clear the text mode of window
printf("\n\t
--------MENU-----------");
printf("\n\t1.Concatenation of Two
Strings");
printf("\n\t2.Find out the String
Length");
printf("\n\t3.Comparison of Two
Strings");
printf("\n\t4.Copy One String Into
Another String");
printf("\n\t5.Exit");
printf("\n\t Enter Your Choice==>");
scanf("%d",&ch); //accept choice from user
switch(ch)
{
case 1:
printf("Enter Any two string\n"); //Display the msg
scanf("%s%s",&str1,&str2);//To accept str1 and str2
from user
printf("\n\n Before Concatenate Two Strings Are str1=%s And
str2=%s",str1,str2);
strcat(str1,str2); //use of
string concatenation function
printf("\n\n After concatenation string str1=%s And
str2=%s",str1,str2);
break;
case 2:
printf("Enter Any two string\n");
scanf("%s%s",&str1,&str2);
printf("\n Length of Strings Are==>\n");
printf("\n Length of String %s is
=%d",str1,strlen(str1)); //use of
string length function
printf("\n Length of String %s is =%d",str2,strlen(str2));
break;
case 3:
printf("Enter Any two string\n");
scanf("%s%s",&str1,&str2);
printf("\n\n Comparison of Two Strings==>");
if(strcmp(str1,str2)==0) //compare strings by using string copy function
{
printf("%s and %s are equal string",
str1,str2);
}
else
{
printf("\n\n%s and %s are not equal
string",str1,str2);
}
break;
case 4:
printf("Enter Any two string\n");
scanf("%s%s",&str1,&str2);
printf("\n\n\n Copy One String into Strings==>");
printf("\n\n Befor copping string str2 to str1
str1=%s,str2=%s",str1,str2);
strcpy(str1,str2); //string copy
function
printf("\n\n After coppying string str2 into str1 string str1=%s
and string str2=%s",str1,str2);
break;
case 5:
exit(0);
break;
default:
printf("\n\t Invalid Choice");
break;
}
getch();
//To get quick output window
}
//------------------- End of Mian Function ----------------------------
/*-----------------<< OUTPUT SCREEN >>-------------------*/
--------MENU-----------
1.Concatenation of Two Strings
2.Find out the String Length
3.Comparison of Two Strings
4.Copy One String Into Another String
5.Exit
Enter Your Choice==>1
Enter
Any two string
jai
hind
Before Concatenate Two Strings Are str1=jai
And str2=hind
After concatenation string str1=jaihind And
str2=hind
--------MENU-----------
1.Concatenation of Two Strings
2.Find out the String Length
3.Comparison of Two Strings
4.Copy One String Into Another String
5.Exit
Enter Your Choice==>2
Enter
Any two string
jay
maharashtra
Length of Strings Are==>
Length of String jay is =3
Length of String maharashtra is =11
--------MENU-----------
1.Concatenation of Two Strings
2.Find out the String Length
3.Comparison of Two Strings
4.Copy One String Into Another String
5.Exit
Enter Your Choice==>3
Enter
Any two string
jay
jay
Comparison of Two Strings==>jay and jay are
equal string
--------MENU-----------
1.Concatenation of Two Strings
2.Find out the String Length
3.Comparison of Two Strings
4.Copy One String Into Another String
5.Exit
Enter Your Choice==>3
Enter
Any two string
jay
jai
Comparison of Two Strings==>jay and jai are
not equal string
--------MENU-----------
1.Concatenation of Two Strings
2.Find out the String Length
3.Comparison of Two Strings
4.Copy One String Into Another String
5.Exit
Enter Your Choice==>4
Enter
Any two string
jai
hind
Copy One String into Strings==>
Befor copping string str2 to str1
str1=jai,str2=hind
After coppying string str2 into str1 string
str1=hind and string str2=hind
--------MENU-----------
1.Concatenation of Two Strings
2.Find out the String Length
3.Comparison of Two Strings
4.Copy One String Into Another String
5.Exit
Enter Your Choice==>5
--------MENU-----------
1.Concatenation of Two Strings
2.Find out the String Length
3.Comparison of Two Strings
4.Copy One String Into Another String
5.Exit
Enter Your Choice==>11
Invalid Choice
No comments:
Post a Comment