pTutorial

New way to learn C programming

C Program to compare two sting

In this section you can learn, how to compare two strings using strcmp function from string.h library and also without using pre-defined function.

Compare two string



#include <stdio.h>
#include <string.h>
#include <conio.h>
void main()
{
   char z[90], x[90];
 
   printf("Enter 1st string\n");
   gets(z);
 
   printf("Enter 2nd string\n");
   gets(x);
 
   if( strcmp(z,x) == 0 )
      printf("Both are equal\n");
   else
      printf("Both are not equal\n");
 
  getch();
}


Download string compare Program

Output of program

string compare | ptutorial

In this example, first entered two string with the help of gets function and after that use strcmp function to compare these two strings, if it returns 0 that means both strings are equal otherwise not equal.

See Also

How to validate a url in php   |   Php string   |   Php fatal error warning and notices

QUOTES OF THE DAY

Eat to live, and not live for eat.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER