Wednesday, February 22, 2017

Compare equality of two string in C

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

int main()
{
    char* country = "Bangladesh";
    char* country2;

    printf("Enter country: ");
    country2 =  malloc(256);
    scanf("%255s", country2); // Don't read more than 255 characters

    if (strcmp(country, country2) == 0)
    {
        printf("True\n");
    }
    else
    {
        printf("False\n");
    }
    return 0;
}

No comments:

Post a Comment

Compare equality of two string in C

#include <stdio.h> #include<string.h> int main() {     char* country = "Bangladesh";     char* country2;     ...