Program for comparison between two strings :-
#include<stdio.h>
#include<string.h>
main()
{
char a[100], b[100];
printf("Enter the first string\n");
gets(a);
printf("Enter the second string\n");
gets(b);
if( strcmp(a,b) == 0 )
printf("Entered strings are equal.\n");
else
printf("Entered strings are not equal.\n");
return 0;
}
Program for copy of two strings :-
#include<stdio.h>
#include<string.h>
main()
{
char source[] = "C program";
char destination[50];
strcpy(destination, source);
printf("Source string: %s\n", source);
printf("Destination string: %s\n", destination);
return 0;
}
Program for String Reverse :-
#include<stdio.h>
#include<string.h>
main()
{
char arr[100];
printf("Enter a string to reverse\n");
gets(arr);
strrev(arr);
printf("Reverse of entered string is \n%s\n",arr);
return 0;
}
Program for Append the two Strings :-
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char a[100], b[100];
printf("Enter the first string\n");
gets(a);
printf("Enter the second string\n");
gets(b);
strcat(a,b);
printf("String obtained on concatenation is %s\n",a);
getch();
return 0;
}
0 comments:
Post a Comment