[Solved] how to use strcmp in g++


The problem isn’t on the function but on the way that you’re using it.

int strcmp ( const char * str1, const char * str2 );

strcmp takes two const char * arguments.

The error tells you that you are giving the function a char so the problem is on the types of personalNo and/or pcode. Your mistake is probably on the declaration of the type of those two variables. You would want to change their type to char * as char only stores one character while char * is an array of characters.

Also, an another way to compare two strings in C++ is to use std::string. Then you can just do the following (provided that both personalNo and pcode are std::string:

if (a[i].personalNo != pcode){
    #some code
}

0

solved how to use strcmp in g++