To compare the given two string using pointers
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
char *str1, *str2 ;
clrscr();
printf("Enter the first string : ");
scanf("%s", str1);
printf("\nEnter the second string : ");
scanf("%s", str2);
while(*str1 == *str2 && (*str1 != '\0' || *str2 != '\0'))
{
str1++;
str2++;
}
if(*str1 == '\0' && *str2 == '\0')
printf("\nThe given strings are equal");
else
printf("\nThe given strings are not equal");
getch();
}
Output:
Case: 1
Enter the first string : cse
Enter the second string : ece
The given strings are not equal
Case: 2
Enter the first string : mech
Enter the second string : mech
The given strings are equal
-
UpdatedDec 31, 2019
-
Views4,689
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order