String Operations
String Operations
// 2. String Comparison
//Using strcmp() built-in function
#include<stdio.h>
#include<string.h>
void main()
{
int d=0;
char a[20],b[20];
puts("Enter the string 1\n");
gets(a);
puts("Enter the string 2\n");
gets(b);
d=strcmp(a,b);
if(d==0)
printf("Both strings are equal");
else
printf("Both strings are not equal");
}
Output:
Enter the string 1
Welcome
Enter the string 2
Welcome
Both strings are equal
// 4. String Copy
// Using strcpy() built-in function
#include<stdio.h>
#include<string.h>
void main()
{
char a[20],b[20];
printf("Enter the string to be copied\n");
gets(a);
strcpy(b,a);
puts("The string is copied");
puts(b);
}
Output:
Enter the string to be copied
Good
The string is copied