Contact Learn C
Copy

Program 191:To Compare 2 strings using Pointers

Program 191:
 
 #include<stdio.h>
main()
{
  char s1[25],s2[25],*t1,*t2;
int cmp=0;
  printf("Enter a string 1\n");
  scanf("%s",&s1);
  printf("Enter a string 2\n");
  scanf("%s",&s2);
  t1=s1;//copying base address of string
  t2=s2;
  while(*t1!='\0'&&*t2!='\0')
  {
    if(*t1!=*t2)
    {
     cmp++;
    }
    t1++;
    t2++;
  }
  
  if(cmp==0)
  {
   printf("Both are equal\n");
  }
  else
  {
   printf("Both are not equal\n");
  }
}

Explanation:

//Coming Soon...

Output:

To Compare 2 strings using Pointers







 
Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide