Converting String to char* error

Hi, i am making little big (not so big) project and i have a problem. In my library i have a function lcd_print which i am using to printing text or whatever i want to lcd. It look like that.

void lcd_print(char* text){

In my main program, I am trying to use this function and as a parameter i am sending String or double. For example

String signCounter = '"Blabla";

But i got typical error:

  • error: cannot convert 'String' to 'char*' for argument '1' to 'void lcd_print(char*)'

So i tried to use it like this:
but it didnt work.

I cant just use function lcd.print(), bcs i have declared lcd in library with function
void lcd_print(char* text) and i cant double it.

I tried everything I could think of, but it didnt work like i want.
I hope u can help me and that u understood what i mean with all it :smiley:

Friendly note: please use the code formatting in your post, it will make it so much easier to read your code and increase the chance that someone will help you.

to convert string to char string in c++ try this:

What does the lcd.printstr() function look like? Commonly you would overload the lcd_print function to accept String in addition to char*, but that would require that lcd.printstr() also accept String. Additionally, it is a good idea to have the char* declared const, in case you want to give the function a text literal.

void lcd_print(String text){

void lcd_print(const char* text){

You can also avoid the String entirely:

char signCounter[] = "Blabla";

Ty, this helped me, but i still have problem with double to char* and float to char* error.

For clarification:
I am doing alarm clock and i am printing time and date to lcd. I am using DHT library and print look like this.


for float i am printing stopwatch

actualTime = (millis() - startTime) / 1000.0;

Which library are you using for the LCD?

< edit >
Most libraries would inherit from the print class, so you can just use lcd.print() for any type variable. Not sure what the lcd.printstr() function is intended to do that cannot be done with lcd.print(), or why you are going through your own lcd_print() function.

I am using LiquidCrystal_I2C library.

This is my library called lcd_wrapper

#include <Arduino.h>
#include <LiquidCrystal_I2C.h>
#include "lcd_wrapper.h"
LiquidCrystal_I2C lcd(0x27,16,2);

void lcd_init()

void lcd_clear()

void lcd_set_cursor(int y, int x)
lcd.setCursor(y, x);

void lcd_print(char text){*

void lcd_print_at(int y, int x, char text){*
lcd_set_cursor(y, x);

and this is a part of main code. I have there more functions, but i just post 1

#include "alarm_clock.h"
#include "lcd_wrapper.h"

void temp_hum()
int readDHT = DHT.read11(dht_apin);

lcd_print("Temp: ");
lcd_print("Hum: ");


Yes i could just remove my void lcd_print(char text)* and use lcd.print from lcd library, but i got error, that in my main program lcd is not declared and idk why. My lcd is declared in library bcs of this function.


So it's a "XY problem", your real problem is that you don't know how to make lcd available in your main sketch.

What is the purpose of your lcd_wrapper library ? It looks like you want to extend the LiquidCrystal_I2C class, so I suggest you learn about class inheritance :wink:

Not exactly what i wanted but never mind.

I already fix it. Ty all for help

Glad you have solved your problem. However, this forum is not only for us to ask for help, it is a reference for anyone who may have the same problem later.

Therefore, even if you have solved an issue on your own, you should explain your solution in the thread so that other people can learn from it.

It is your function you can overload it for different types even to take string. For the future use const char* to pass strings so you could pass literals as well.

Ok, my bad, sorry :slight_smile:

I specify my problem again for better understanding.

I made my own library where i made my own methods for working with lcd. But if i wanted to print something with lcd.print i could not use it. So i had to made something like setter method.

void lcd_print(char text){*

I wanted to use this, bcs this method i got in my last project (it is school project). Command lcd.print() can print int, float, string, double etc. But there i had as a paramether char, so i made close same methods for int, double, string.

void lcd_print_float(float text){

void lcd_print_double(double text){

void lcd_print_string(String text){

It is not the best solution but it works. Yes i could do it easy and just use LiquidCrystal_I2C library. in my main program, but i wanted to separate them for better code look.

If I could publish the whole project here, it would be better.
Again, thanks all for help and patience :slight_smile:

What is stopping you ?

I thought this was a typo at first but you brought this again, so what is the asterisk * for?

Just mistake in formatting. Sorry

If i wanted to upload file i got an error, that i cant do it, bcs i am new here. I could do it through gitHub, but i forgot about that way :smiley:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.