Check whether two strings are the same in C language

www.‮ttual‬uri.com
Check whether two strings are the same in C language

Strcmp()The function compares two strings and returns an integer value.

#include <stdio.h>
#include <string.h>
int main(void)
{
  //variable
  char str1[100], str2[100];
  
  //input
  printf("Enter string 1: ");
  gets(str1);
  
  printf("Enter string 2: ");
  gets(str2);
  
  if (strcmp(str1, str2) == 0) {
    printf("Both are same.\n");
  }
  else {
    printf("Both are different.\n");
  }
  printf("End of code\n");
  return 0;
}

when the strings are same:

Enter string 1: Apple
Enter string 2: Apple
Both are same.
End of code
Created Time:2017-08-28 07:07:50  Author:lautturi