ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]_

In file included from C:\Users\okury\Documents\Arduino\libraries\DS3231/DS3231.h:27:0,
from C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:5:
C:\Users\okury\Documents\Arduino\libraries\DS3231/hardware/avr/HW_AVR_defines.h:2:0: warning: "cbi" redefined
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))

In file included from C:\Users\okury\Documents\Arduino\libraries\URTouch/URTouch.h:30:0,
from C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:2:
C:\Users\okury\Documents\Arduino\libraries\URTouch/hardware/avr/HW_AVR_defines.h:2:0: note: this is the location of the previous definition
#define cbi(reg, bitmask) *reg &= ~bitmask

C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino: In function 'void loop()':
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:218:30: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("MENU", 5, 5);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:219:41: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("Set Alarm", CENTER, 20);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:234:30: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("H", 54, 122);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:235:31: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("M", 150, 122);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:238:32: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("SET", 236, 67);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:240:35: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("CLEAR", 220, 122);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:287:51: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("Alarm set for:", CENTER, 165);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:318:41: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("ALARM", CENTER, 90);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:322:44: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("DISMISS", CENTER, 150);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino: In function 'void drawHomeScreen()':
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:354:26: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("T:", 7, 7);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:356:26: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("C", 82, 7);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:358:26: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("o", 74, 5);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:361:47: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("von Okur Yusuf", CENTER, 215);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:365:44: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("Alarm set for: ", 68, 215);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino: In function 'void drawMusicPlayerScreen()':
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:377:28: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("MENU", 5, 5); // Prints the string on the screen
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:382:59: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("by www.HowToMechatronics.com", CENTER, 215); // Prints the string on the screen
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:393:29: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("0:00", 8, 48);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:394:32: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("-0:00", 276, 48);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino: In function 'void trackPlayTime()':
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:488:27: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print(":", 16, 48);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:490:28: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print("-", 276, 48);
^
C:\Users\okury\Desktop\Arduino_Touch_Screen_Music_Player_und_Wecker\Arduino_Touch_Screen_Music_Player_und_Wecker.ino:492:28: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
myGLCD.print(":", 292, 48);
^
Sketch uses 99788 bytes (39%) of program storage space. Maximum is 253952 bytes.
Global variables use 723 bytes (8%) of dynamic memory, leaving 7469 bytes for local variables. Maximum is 8192 bytes.

Hello guys can anyone help me please?

Read the forum guidelines to see how to properly post code and error messages.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Post code.
In code tags.
Post error messages.
Not pictures - we are not ancient Egyptians

That should be 'char*' not 'char' in the title, and the warning is caused by the function in the library expecting a char*, but you are giving it a const char*. As long as the library is not attempting to modify the data pointed to by the char* then the warning can be ignored.

Sorry :frowning:

I think I've run into this before. Tell me if this sounds right: You got something that's a String variable, as in String message="hello world"; and your passing it to a function that's complaining about the const char* thing. I believe your solution here is to pass message.c_str() instead. This happens because the function you're calling is expecting the old school C-style null terminated array of characters type of a string. Adding the .c_str() method will convert it to what the function expects.

Not quite, the majority of the warnings are for function calls like this:

myGLCD.print("DISMISS", CENTER, 150);

The library appears to be UTFT from Rinky Dink Electronics, which has the function header

     void  print(char *st, int x, int y, int deg=0);

The text literal, "DISMISS" in this case, passes a const char* , not a char*, which generates a warning because a text literal should not be altered by a function, but char* without the const indicates the function would be allowed to make alterations. The warning can be ignored as long as the function does not actually make any changes to the memory pointed to by the char*.

Note that on some platforms, such as the ESP8266, this will generate an error instead of a warning, and will need to be fixed in the library.

Some libraries are written better than other. Not in this case though. print expects char* for no good reason


void print(char *st, int x, int y, int deg=0);

There is another overload that expects String in place of char* you can use that to avoid warnings.


myGLCD.print(String("MENU"), 5, 5);