Comparing the values of char arrays in C++

后端 未结 5 1930
广开言路
广开言路 2021-01-02 02:38

I have problem about doing something in my program. I have a char[28] array keeping names of people. I have another char[28] array that also keeps names. I ask user to enter

5条回答
  •  抹茶落季
    2021-01-02 03:21

    The problem is in if(sName==Student.name) which basically compares the address of the arrays, not their values.
    Replace it with (strcmp(sName, Student.name) == 0)

    But in general, you are working on C++, not C, I would advise working with std::string which will make this much simpler.

提交回复
热议问题