C program to compare two string using strcmp function.

Posted by Mangesh on April 12, 2018

/* compare to two using strcmp function. */

Description :

In C we have inbuilt function to compare two string. this function ic called strcmp(). It accept two string parameter and returns int value.
It returns 0 if both strings are equal.
else it returns positive or negative integer if both strings are not equal.

Program :

void main()
  char str1[20],str2[20];
  printf("Enter the first string : ");
  printf("Enter the second string : ");
  if(strcmp(str1,str2) == 0)
    printf("Both strings are equal!");
    printf("Both strings are not equal!");

Output :

c program for strcmp Executed and tested in Turbo C 3.2

Written with from Mangesh.

Related Post
1 C program for naive string matching algorithm.
2 C program to check whether the given string is palindrome or not.
3 C program to concatenate two string.
4 C program to check whether two strings are anagram or not.
5 C program to reverse the string.
6 C program to replace a character in a string.
7 C program to compare two string.
8 C program to compare two string using strcmp function.
Latest Post
1 C program to implement Queue using linked list.
2 C program for binary search tree (BST).
3 C program to search an element in linked list.
4 C program for postorder traversal in binary tree.
5 C program for preorder traversal in binary tree.