Logo 
Search:

C Programming Articles

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

Program to compare one string s2 to another string s1 and also first unmatched characters without using strcmp function from string.h

Posted By: Volney Fischer     Category: C Programming     Views: 3049

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 and also first unmatched characters without using strcmp function from string.h 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 : MCA001

 Please Give The STRING TO B : MCa001

 THE DIFFERENCE BETWEEN IS HERE -32



--------------------------------------------------------------------------
  
Share: 



Volney Fischer
Volney Fischer author of Program to compare one string s2 to another string s1 and also first unmatched characters without using strcmp function from string.h is from Frankfurt, Germany.
 
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!