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 using strcmp function from string.h

Posted By: Adalberto Fischer     Category: C Programming     Views: 2937

Write a program to compare one string s2 to another string s1. Print the difference of first unmatched characters 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 using strcmp function from string.h in C Programming

#include<stdio.h>
#include<conio.h>
void main()
{
    char a[21],b[21];
    int i;
    clrscr();
    printf("\n Please Give The STRING OF A : ");
    gets(a);

    flushall();
    printf("\n Please Give The STRING TO B : ");
    gets(b);


    i = strcmp(a, b);

    if(i < 0)
        printf("\nFIRST MISMATCHED CHARACTER IS %d NUMBER  LESS",i*-1);
    elseif (i > 0)
        printf("\nFIRST MISMATCHED CHARACTER IS %d NUMBER  HIGHER",i);
    else
       printf("both are same than \n");


    getch();
}


--------------------------------- OUTPUT ---------------------------------



 Please Give The STRING OF A : MCA001

 Please Give The STRING TO B : MCa001



FIRST MISMATCHED CHARACTER IS 32 NUMBER  LESS


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



Adalberto Fischer
Adalberto Fischer author of Program to compare one string s2 to another string s1. Print the difference of first unmatched characters using strcmp function from string.h is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 

Other Interesting Articles in C Programming:


 
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!