My Subject Blog

C Program to Compare Two String Using Pointer

/*
Write a program using a pointer to compare two strings. 
*/

#include <stdio.h>

int main(void) 
{
char str1[50],str2[50];
int i,j;
char *p,*q;
printf("\n Enter First String : ");
scanf("%s",str1);
printf("\n Enter Second String : ");
scanf("%s",str2);
p=str1;
q=str2;
for(i=0;*(p+i)!='\0';i++)
{
if(*(p+i) != *(q+i))
{
break;
}
}
if(*(q+i)=='\0')
{
printf("\n Both String are Equal");
}
else
{
printf("\n Both String are Not Equal");
}
return 0;
}

Comments

Most Visited Post

C Program to Find Largest Odd Number from Array

C Program for Runtime Memory Allocation for Table of Integers

Followers