strcmp conversion from ‘char’ to ‘const char*’

15,620

wood is of type char: it must be a string, ie, char*, to be used in strcmp().

Change to:

while ('m' != wood && 'j' != wood && 'o' != wood)
Share:
15,620
Daniel Del Core
Author by

Daniel Del Core

Updated on June 14, 2022

Comments

  • Daniel Del Core
    Daniel Del Core almost 2 years

    I'm having a problem with strcmp.

    This is my code.

    while (strcmp("m",wood) !=0 || strcmp("j",wood) !=0 || strcmp("o",wood) !=0){
        cout << "(m for mahogany, o for oak, or p for pine): ";
    cin >> wood;
    }
    

    And this is my error:

    dining.cpp: In member function ‘void DiningSet::woodType()’:
    dining.cpp:76:24: error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive]
    /usr/include/string.h:143:12: error:   initialising argument 2 of ‘int strcmp(const char*, const char*)’ [-fpermissive]
    dining.cpp:76:48: error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive]
    /usr/include/string.h:143:12: error:   initialising argument 2 of ‘int strcmp(const char*, const char*)’ [-fpermissive]
    dining.cpp:76:72: error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive]
    /usr/include/string.h:143:12: error:   initialising argument 2 of ‘int strcmp(const char*, const char*)’ [-fpermissive]
    
  • Alok Save
    Alok Save about 12 years
    This answer is correct, @Daniel D C, add to that what my comment says under the Q for better understanding.
  • T I
    T I about 12 years
    @DanielDC I think take a look at char and string literals in addition too the answer :)
  • Daniel Del Core
    Daniel Del Core about 12 years
    Thanks guys ! appreciate the quick response !
  • zszen
    zszen over 8 years
    char compare only use "==" and with single char include with " ' "