error message invalid conversion from 'const char*' to 'char' [-fpermissive]

Hi All,

i want to store some data on my local or SD storage.
I found a library (EDB) that is able to do this.

So I have to contruct the table first:

struct LogEvent {
  int gebruikerid;
  char tijd[8];
  char datum[10];
} 
logEvent;

and then I want to fill the database records with this data for example:

logEvent.gebruikerid = 1; 
logEvent.tijd[8] = {"13:51:00"};
logEvent.datum[10] = {"01/08/2017"};
db.appendRec(EDB_REC logEvent);

when I verify the code it fails on but tijd and datum records.
im new to arduino so probably im doing something wrong.

anybody how could point me in the right direction ?

thx !

Bauke

logEvent.tijd[8] = {"13:51:00"};

logEvent.tijd only has eight elements, so accessing the ninth element is pointless.
Even if you meant to use strcpy, you need nine elements to store an eight character string.

thx AWOL,

I have changed the length of the array. but the error is still the same.

its something about the declaration of the variables...

bauke

Use strcpy to fill up the memory buffer of your struct with the string

You can't initialize your buffer the way you do it. It is not the correct way to do an array or cstring assignment in C

logEvent.tijd[8] is the 9th element (which is beyond your array size as AWOL pointed to give you a hint) of your buffer and is of type character (char). If that memory was legit what you can store in there is a char or anything that can be converted to a char. logEvent.tijd[5] = 'A'; would be OK because 'A' is a char.

{"13:51:00"} is an array of 1 element of type pointer to a constant string (const char *)

So when you do logEvent.tijd[8] = {"13:51:00"}; you are trying to store In a (overflown) memory location designed for a char a pointer to a constant string which obviously makes no sense at all, hence the compiler telling you invalid conversion from 'const char*' to 'char'

thx

first I thought that the strcpy was some type of typo :slight_smile:
i have looked up the command and now this part is working :slight_smile: !

thanks

i used this site as a guide:

https://beej.us/guide/bgc/output/html/multipage/strcpy.html

baukepluggee:
error message invalid conversion from 'const char*' to 'char'

Regardless of your code, the error you are getting occurs when you try to place the contents of one variable type into another that doesn't match. Here's an example:

void send (const char *buffer)
{
    char *bufptr;
    bufptr = buffer; // make a movable buffer pointer
    // ...............
}

That code will give you the "invalid conversion from 'const char*' to 'char'" error because the compiler can't make a non-constant variable (bufptr) into a constant variable (buffer).

The solution is to typecast the variable - like this:

void send (const char *buffer)
{
    char *bufptr;
    bufptr = (char *) buffer; // make a movable buffer pointer
    // ...............
}

See? The "(char *)" before "buffer" means "think of buffer as a "char *" and not as a "const char *".

Make sense?

1 Like

yes that make sense !

thx for the clarification