Strcmp() function example program in C C++

Strcmp() function example program in C C++

C Language में उपलब्ध Operators और इनके विभिन्न प्रकारो को जानने के लिए देखें—Operators in C

C Language में Character Array या String किसे कहते है जानने के लिए देखें हमारा यह पोस्ट— Strings in C

C-Language में Operator Precedence और Associativity Rule क्या होता है जानने के लिए देखें— Precedence and Associativity in C

Strcmp() function example program in C

#include<stdio.h>
#include<string.h>
int main()
{
    char str1[20],str2[20];
    int dif;
    printf("Enter string1 : ");
    scanf("%s",&str1);
    printf("Enter string2 : ");
    scanf("%s",&str2);
    dif=strcmp(str1,str2);
    if(dif==0)
        printf("Same string");
    else
        printf("Not a same string");
    return 0;
}

Strcmp() function example program in C++

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char str1[20],str2[20];
    int dif;
    cout<<"Enter string1 : ";
    cin>>str1;
    cout<<"Enter string2 : ";
    cin>>str2;
    dif=strcmp(str1,str2);
    if(dif==0)
        cout<<"Same string";
    else
        cout<<"Not a same string";
    return 0;
}

Output of Strcmp() function example program in C C++

Strcmp() function example program in C C++

Related string based programs in C C++

  1. String input-output without space
  2. String input-output with space
  3. Strlwr() function example program
  4. Strupr() function example program
  5. Strlen() function example program
  6. Strrev() function example program
  7. Strcpy() function example program
  8. Strcat() function example program
  9. String and Pointer
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer