#include<stdio.h>
#include<string.h>
void main()
{
    char str[20],cmp[20];
    int x;
    printf("enter the string :  ");
    gets(str);
    printf("enter the string 2 : ");
    gets(cmp);
    x=strcmp(str,cmp);
    printf("%d",x);
}

my doubt is how strcmp returns an integer ??how will it take the words

strcmp returns the difference of the two strings. If the first string is "less" than the second string it returns a value less than 0. If the first string is "greater" than the second string it returns a value greater than 0. And if the two strings are identical, it returns 0.

Here's an example implementation:

int my_strcmp(char const* a, char const* b)
{
    // Find the first two characters that don't match
    while (*a == *b && *a)
    {
        ++a;
        ++b;
    }

    // Compare the mismatched characters and return the absolute difference
    if (*a < *b)
    {
        return -1;
    }
    else if (*a > *b)
    {
        return +1;
    }
    else
    {
        return 0;
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.