How to use strcmp function to compare two strings in C

#include <stdio.h>
#include <string.h>

int main(void)
{
    const char *s1 = "Hello World";
    const char *s2 = "Hello World";
    if (strcmp(s1, s2) == 0)
    {
        printf("The strings are equal.\n");
    }
    else
    {
        printf("The strings are not equal.\n");
    }

    return 0;
}

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *