This is a simplification of my situation:
header.h
#DEFINE NUMBER 3
extern char reserved[][];
definer.c
char reserved[NUMBER][4] = {"WOW","LOL","K"}
sign.c
#include "header.h"
void theFunctionWithTheError{
if (reserved[1] == "I love stackoverflow"){ /**THE LINE OF THE ERROR*/
return;
}
}
in sign.c, I get the error Expression must be a pointer to a complete object type
for the word reserved
What do you suggest me to do?
The error message says that you cannot usefully use the declaration extern char reserved[][];
because the compiler needs at least the second dimension of the array to know how to access parts of the array — so it needs to be extern char reserved[][4];
. With that declaration, it is immediately clear that "I love Stack Overflow"
(regardless of word breaks and capitalization) is far too long to be equal to any of the strings in the array, but that's somewhat incidental.
You can't usefully compare strings like that — you need to use strcmp()
. See How do I check if a value matches a string? and How do I properly compare strings? amongst many other possible SO questions.
You have:
if (reserved[1] == "I love stackoverflow")
You need:
if (strcmp(reserved[1]), "I love Stack Overflow") == 0)
or equivalent. Explicitly comparing the result of strcmp(A, B)
with 0
using any op
from the set ==
, !=
, >=
, <=
, >
or <
matches the result you would get from A op B
if strings were real built-in types in C.