Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

(strcmp) printed out the 0 and 1 at the end of the if statement that I wrote

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

int main()
{
    char string1[] = "Abc";
    char string2[] = "Abc";
int result = strcmp(string1, string2);

    if(result == 0)
    {
        printf("These string are the same ");
    }
    else
    {
        printf("These string are not the same ");
    }

    printf("%d", result);

    return 0;
}

I expected the output would be "These string are the same", but it printed out with 0 at the end of the statement. Ex : These string are the same 0. How can I get rid of the number?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You are printing

printf("These string are the same ");

and then

printf("%d", result);

The latter prints the integer value of "result" which is ‘0’ (the result of the comparison)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading