string compare

           

               COMPARE TWO STRINGS


#include<stdio.h>
#include<conio.h>
void main()
   {
        char s1[10],s2[10];
         int n1=0,n2=0,i,flag;
          printf("Enter 1st string\n");
         scanf("%s",&s1);
         printf("Enter 2nd string\n") ;
        scanf("%s",&s2);
   for(i=0;s1[i]!='\0';i++)
       n1++;
   for(i=0;s2[i]!='\0';i++)
       n2++;
 
  if(n1==n2)
    {
       flag=0;
for(i=0;i<n1;i++)
  {
     if(s1[i]==s2[i])
      flag=1;
  }
      if(flag==1)
    printf("Two strings are equal");
    }
else
   printf("Two strings are not equal");
   getch();
   }

No comments:

Post a Comment

If you have any problems related to solutions or any concept please let me know.

Copyright (c) 2020 Custom Programs All Right Reserved

Pages