Compare two strings using pointer | My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Sunday, March 1, 2020

Compare two strings using pointer | My CS Tutorial

C PROGRAM CODE



#include<stdio.h>
main()
{
  char s1[25],s2[25],*t1,*t2;
int cmp=0;
  printf("\n ENTER FIRST STRING:\n ");
  scanf("%s",&s1);
  
  printf("\n ENTER SECOND STRING:\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("\n BOTH ARE EQUAL.\n ");
  }
  else
  {
   printf("\n BOTH ARE NOT EQUAL.\n ");
  }
}


OUTPUT:






No comments:

Post a Comment