Comparing chars in C++ - argument of type "char" is incompatible with parameter of type "const char *

Gavin Crawley picture Gavin Crawley · Aug 14, 2013 · Viewed 10k times · Source

Im trying to compare 2 values in C++ (which im new to so please go easy)

struct styles{
int itemNo;
char desc[26]; 
char brand[21]; //between 3 - 20
char category;
double cost;
};  

struct declared above, then im using this code in another function

char cat[2];
for (x=0;x<size;x++)
{

    if (strcmp(cat,styleAr[x].category)==0)

its giving me an error with the 'styleAr[x].category' in the if statement: argument of type "char" is incompatible with parameter of type "const char *

any explanations on how I could solve this would be great

Answer

mark picture mark · Aug 14, 2013

You have category as a single char and cat is an array of chars (i.e. a char *)... you probably didn't mean to compare a string with a single character