Receive and compare strings

Asked 2 weeks ago, Updated 2 weeks ago, 2 views

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main (){



        character[100] = "; //array initialization
        scanf(" %s", order);
        if (order[100] == "Chess") //Compare saved strings 
            printf("yes");

        else
        return 0;


}

I want to get a string into the array and make sure that the stored string is "Chess" I wonder where the wrong part of the code is.

c

2022-09-20 08:55

1 Answers

order[100] == "Chesse"

The code above is the problem. The C language does not provide the == operator for the string. Change the code above as below.

#include <string.h>

if (strcmp(order, "Chesse")==0)
    printf("yes");


2022-09-20 08:55

If you have any answers or tips


© 2022 pinfo. All rights reserved.