Receive and compare strings

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

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

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

        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.


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)

2022-09-20 08:55

If you have any answers or tips

© 2022 pinfo. All rights reserved.