Fpermissive going to kill me

Can someone please tell me which variables are char and const char* in this message?

In function 'void logger(int, char, float)':
main:1001:21: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
     strcpy(tmp, text);
                     ^

This is the code, stripped for testing purposes:

void logger(int level,char text,float val /*=NULL*/) {
 
  char tmp[450];
  strcpy(tmp, text);

}

Apparently I will die without understanding how chars work but I am trying. Part of what I don't understand here is where the const designation is coming from. The supposed-to-be-helpful carat is pointing to a close parenthesis. So which variable is magically a const when I've declared neither as such? (At least not on purpose).

I believe you meant to write

void logger(int level,char *text,float val /*=NULL*/) {

Notice the "*" in front of text? That makes it a pointer to char rather than a char.

strcpy(char *,char); is what it ended up objecting to.

Thank you both for your replies, which do make things clearer for me. But what about the "const" in the error message. Are char arrays constant by default? It feels misleading to me when I haven't declared tmp as const char yet the error indicates a const char is involved here.

Just look up the definition of strcpy:

char * strcpy ( char * destination, const char * source );
1 Like

And once again the brick wins because after banging my head on it long enough, I couldn't see the simple answer.

Thanks again.

This is a really great explanation. Wish I could mark two solutions.

You may only be able to give one :white_check_mark: but you can give as many :heart: as you like. :slight_smile:

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