Thread: Problem argument of type "char" is incompatible with parameter of type "char *"

  1. #1
    Registered User
    Join Date
    Jun 2020
    Posts
    2

    Problem argument of type "char" is incompatible with parameter of type "char *"

    Hello i am programing arduino but i have a little problem.
    so Here is my part of my code:
    Code:
    void play_game(char *secret)
    {
      char **history;
      char *guess;
      int pokus = 0;
      int peg_a;
      int peg_b;
      int Chistory = 0;
    
      guess[0] = 0;
      guess[1] = 1;
      guess[2] = 2;
      guess[3] = 3;
      char *k = (char *) guess[0];
    
      turn_off_leds();
      lcd_clear();
    
      lcd_print_at(1, 2, "Welcome");
      lcd_print_at(1, 2, "Your goal");
    
      while (true) {
        delay(100);
        if (digitalRead(BTN_ENTER_PIN == HIGH)) {
          break;
        }
      }
      lcd_clear();
      lcd_print_at(0, 1, "I think");
      lcd_print_at(0, 2, "Your ate");
      lcd_print_at(12, 2, k);
      lcd_print_at(13, 2, guess[1]);
      lcd_print_at(14, 2, guess[2]);
      lcd_print_at(15, 2, guess[3]);
    
      while (true) {
        if (digitalRead(BTN_1_PIN) == HIGH &&
            digitalRead(BTN_2_PIN) == LOW &&
            digitalRead(BTN_3_PIN) == LOW && digitalRead(BTN_4_PIN) == LOW) {
          if (guess[0] == 9) {
            guess[0] = 0;
          } else {
            guess[0]++;
          }
          lcd_print_at(12, 2, (char *) guess[0]);
          lcd_print_at(13, 2, guess[1]);
          lcd_print_at(14, 2, guess[2]);
          lcd_print_at(15, 2, guess[3]);
    lcd_print_at is declared:
    Code:
          void lcd_print(char *text) {
            Serial.print(text);
            lcd.print(text);
          }
    
          void lcd_print_at(int y, int x, char *text) {
            lcd_set_cursor(y, x);
            lcd_print(text);
          }
    and my error look like this:
    Code:
    src\master.cpp:178:31: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
         lcd_print_at(1,2,"Welcome");
                                   ^
    src\master.cpp:179:33: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
         lcd_print_at(1,2,"Your goal");
                                     ^
    src\master.cpp:191:30: warning: invalid conversion from 'char' to 'char*' [-fpermissive]
         lcd_print_at(13,2,guess[1]);
                                  ^
    In file included from src\master.cpp:2:0:
    src\lcd_wrapper.h:50:6: note:   initializing argument 3 of 'void lcd_print_at(int, int, char*)'
     void lcd_print_at(int y, int x,char* text);
          ^
    src\master.cpp:192:30: warning: invalid conversion from 'char' to 'char*' [-fpermissive]
         lcd_print_at(14,2,guess[2]);
                                  ^
    In file included from src\master.cpp:2:0:
    src\lcd_wrapper.h:50:6: note:   initializing argument 3 of 'void lcd_print_at(int, int, char*)'
     void lcd_print_at(int y, int x,char* text);
          ^
    src\master.cpp:193:30: warning: invalid conversion from 'char' to 'char*' [-fpermissive]
         lcd_print_at(15,2,guess[3]);
                                  ^
    In file included from src\master.cpp:2:0:
    src\lcd_wrapper.h:50:6: note:   initializing argument 3 of 'void lcd_print_at(int, int, char*)'
     void lcd_print_at(int y, int x,char* text);
          ^
    src\master.cpp:206:45: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
                 lcd_print_at(12,2,(char*)guess[0]);
                                                 ^
    src\master.cpp:207:38: warning: invalid conversion from 'char' to 'char*' [-fpermissive]
                 lcd_print_at(13,2,guess[1]);
                                          ^
    In file included from src\master.cpp:2:0:
    src\lcd_wrapper.h:50:6: note:   initializing argument 3 of 'void lcd_print_at(int, int, char*)'
     void lcd_print_at(int y, int x,char* text);
          ^
    src\master.cpp:208:38: warning: invalid conversion from 'char' to 'char*' [-fpermissive]
                 lcd_print_at(14,2,guess[2]);
                                          ^
    In file included from src\master.cpp:2:0:
    src\lcd_wrapper.h:50:6: note:   initializing argument 3 of 'void lcd_print_at(int, int, char*)'
     void lcd_print_at(int y, int x,char* text);
          ^
    src\master.cpp:209:38: warning: invalid conversion from 'char' to 'char*' [-fpermissive]
                 lcd_print_at(15,2,guess[3]);
                                          ^
    In file included from src\master.cpp:2:0:
    src\lcd_wrapper.h:50:6: note:   initializing argument 3 of 'void lcd_print_at(int, int, char*)'
     void lcd_print_at(int y, int x,char* text);
          ^
    src\master.cpp:223:38: warning: invalid conversion from 'char' to 'char*' [-fpermissive]
                 lcd_print_at(12,2,guess[0]);
                                          ^
    In file included from src\master.cpp:2:0:
    src\lcd_wrapper.h:50:6: note:   initializing argument 3 of 'void lcd_print_at(int, int, char*)'
     void lcd_print_at(int y, int x,char* text);
          ^
    src\master.cpp:224:38: warning: invalid conversion from 'char' to 'char*' [-fpermissive]
                 lcd_print_at(13,2,guess[1]);
                                          ^
    In file included from src\master.cpp:2:0:
    src\lcd_wrapper.h:50:6: note:   initializing argument 3 of 'void lcd_print_at(int, int, char*)'
     void lcd_print_at(int y, int x,char* text);
          ^
    src\master.cpp:225:38: warning: invalid conversion from 'char' to 'char*' [-fpermissive]
                 lcd_print_at(14,2,guess[2]);
                                          ^
    In file included from src\master.cpp:2:0:
    src\lcd_wrapper.h:50:6: note:   initializing argument 3 of 'void lcd_print_at(int, int, char*)'
     void lcd_print_at(int y, int x,char* text);
          ^
    src\master.cpp:226:38: warning: invalid conversion from 'char' to 'char*' [-fpermissive]
                 lcd_print_at(15,2,guess[3]);

    I dont know what i am doing wrong. Can you help me with my code?
    Last edited by Salem; 3 Weeks Ago at 05:28 AM. Reason: removed eyebleed colour scheme

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,778
    ISO C++ forbids converting a string constant to 'char*'
    These warnings are telling you that you passed a string literal as an argument where the parameter is a char* rather than const char*. The reason why this is a red flag is that what a char* parameter points to could be modified, whereas a string literally cannot be safely modified.

    In your case, the simple solution is to change the parameter to be a const char* since the function really doesn't modify what the pointer points to.

    invalid conversion from 'char' to 'char*'
    These warnings are telling you that you passed a char as an argument, but a char* was expected. You need to turn the char into a string, either in the caller, or by overloading the function.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2020
    Posts
    2
    i did something like this
    Code:
    char **history;
    
    char guess[4];
    int pokus = 0;
    int peg_a;
    int peg_b;
    int Chistory = 0;
    
    guess[0] = 0;
    guess[1] = 0;
    guess[2] = 0;
    guess[3] = 0;
    guess[4] = '\0';
    .... .....lcd_print_at(12, 2, guess[0]);
    lcd_print_at(13, 2, guess[1]);
    lcd_print_at(14, 2, guess[2]);
    ....
    and error is
    Code:
    src\master.cpp: In function 'void play_game(char*)':
    src\master.cpp:193:30: warning: invalid conversion from 'char' to 'const char*' [-fpermissive]
         lcd_print_at(12,2,guess[0]);
                                  ^
    In file included from src\master.cpp:2:0:
    src\lcd_wrapper.h:50:6: note:   initializing argument 3 of 'void lcd_print_at(int, int, const char*)'
     void lcd_print_at(int y, int x,const char* text);
          ^
    src\master.cpp:194:30: warning: invalid conversion from 'char' to 'const char*' [-fpermissive]
         lcd_print_at(13,2,guess[1]);
                                  ^
    In file included from src\master.cpp:2:0:
    src\lcd_wrapper.h:50:6: note:   initializing argument 3 of 'void lcd_print_at(int, int, const char*)'
     void lcd_print_at(int y, int x,const char* text);
          ^
    src\master.cpp:195:30: warning: invalid conversion from 'char' to 'const char*' [-fpermissive]
         lcd_print_at(14,2,guess[2]);
                                  ^
    In file included from src\master.cpp:2:0:
    src\lcd_wrapper.h:50:6: note:   initializing argument 3 of 'void lcd_print_at(int, int, const char*)'
     void lcd_print_at(int y, int x,const char* text);
          ^
    src\master.cpp:196:30: warning: invalid conversion from 'char' to 'const char*' [-fpermissive]
         lcd_print_at(15,2,guess[3]);




    [/FONT][/COLOR]
    Last edited by Salem; 3 Weeks Ago at 09:29 AM. Reason: Eyebleed

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,060
    Please make sure you either 'copy as text' from your IDE, or 'paste as text' in your browser.
    Your copied colour scheme and fonts are an eyesore.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with "double" argument type
    By seanksg in forum C Programming
    Replies: 10
    Last Post: 03-25-2011, 03:22 AM
  2. stdin "incompatible pointer type" as FILE*
    By Jesdisciple in forum C Programming
    Replies: 9
    Last Post: 08-20-2008, 11:44 PM
  3. "assignment from incompatible pointer type"
    By gkoenig in forum C Programming
    Replies: 1
    Last Post: 05-03-2008, 10:38 PM
  4. Replies: 9
    Last Post: 07-07-2006, 11:03 AM
  5. Replies: 2
    Last Post: 05-23-2003, 02:46 PM

Tags for this Thread