Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to compare one string s2 to another string s1. Print the difference of first unmatched characters (Without Using strcmp function)

Posted By: Lauren Hughes     Category: C Programming     Views: 2242

Write a program to compare one string s2 to another
string s1. Print the difference of first unmatched
characters (Without Using strcmp function from string.h)

Code for Program to compare one string s2 to another string s1. Print the difference of first unmatched characters (Without Using strcmp function) in C Programming

#include<stdio.h>
#include<conio.h>
    void main()
    {
        char a[21],b[21];
        int a1,n1,n2,j;
        int i;
        clrscr();
        printf("\n Please Give The STRING OF A : ");
        scanf("%s",a);    
        flushall();
        printf("\n Please Give The STRING TO B : ");
        scanf("%s",b);

        for(i=0,n1=0;a[i]!='\0';i++)
            n1++;
        for(i=0,n2=0;b[i]!='\0';i++)
        n2++;


        if(n1 < n2)
        {
          for(i=0;i<n2;i++)
                 {
            if(a[i]==b[i])
            j=0;
          else
          {
            a1=a[i]-b[i];
            printf(" THE DIFFERENCE BETWEEN IS HERE %d",a1);
            j++;
            break;
               }
      }
    }
    else
    {
     for(i=0;i<n1;i++)
     {
        if(a[i]==b[i])
            j=0;
        else
        {
            a1=a[i]-b[i];
            printf(" THE DIFFERENCE BETWEEN IS HERE %d",a1);
            j++;
            break;
        }
      }
     }

       if(j==0)
        printf(" BOTH ARE EQUALS");


       getch();
    }


************************ OUTPUT ************************************************

     Please Give The STRING OF A : MCA008

     Please Give The STRING TO B : MCA001

     THE DIFFERENCE BETWEEN IS HERE -42

********************************************************************************
  
Share: 



Lauren Hughes
Lauren Hughes author of Program to compare one string s2 to another string s1. Print the difference of first unmatched characters (Without Using strcmp function) is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!