-7

Hi I'm doing an assignment and in this part of it I need to check if a word I have entered into a char array is equal to a word stored in a structure array. This is what I have but it doesn't work:

if (CDdata[i].artist == search)

Can someone please help me compare the item in the structure array to the char array?

Thanks.

4

2 回答 2

1

您可以使用 c 标准库中的strcmp函数。

if (strcmp(CDdata[i].artist, search) == 0)
于 2013-06-10T11:21:32.413 回答
1

假设CDdata[i].artistandsearchchar*or const char*,您当前所做的只是比较指针而不是

您需要使用类似if (strcmp(CDdata[i].artist, search))返回 0 的东西来表示相等。

strcmp是 C 标准库中的标准函数。

于 2013-06-10T11:21:33.440 回答