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

Php function   |   How to enable php pdo extension   |   How to check variable is set or not in php

QUOTES OF THE DAY

Crafty men condemn studies, simple men admire them, and wise use them.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER