Strcmp

The strcmp(first_string, second_string) function compares two strings.
Syntax :
strcmp(first_string, second_string)
Example :

#include <stdio.h>

int main(void)
{
    char firststring[20],secondstring[20];

    printf("Enter first string : ");
    gets(firststring);//reads string from console

    printf("\nEnter second string : ");
    gets(secondstring);

    if(strcmp(firststring,secondstring)==0)
    printf("\nStrings are equal");

    else
    printf("\nStrings are not equal");

}

Post a Comment

0 Comments