Write C++ program to compare two strings using strcmp


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. #define MAX_SIZE 100 //Maximum size of the string
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. char str1[1000], str2[1000];
  10.  
  11. cout<<"Enter the first string"<<endl;
  12. cin>>str1;
  13.  
  14. cout<<"Enter the second string"<<endl;
  15. cin>>str2;
  16.  
  17. if (strcmp(str1,str2) == 0)
  18. cout<<"Entered strings are equal"<<endl;
  19. else
  20. cout<<"Entered strings are not equal"<<endl;
  21.  
  22. return 0;
  23.  
  24. }

Result

C++ language techstudy.org

     





Related Topics




Popular Posts