Help With Passing Characters to Functions

Hi

I'm having some trouble passing characters to functions. Hopefully someone can help.

I have the following statement which passes a text string to a function named scroll(). It's part of a switch statement, which is why 'case' is in there.

 case SCROLL: scroll ("TESTING", 500); break;             // function(text, display time)

I want to append three blank spaces to the string in the scroll function, and then do some further work using the modified string. I'm trying to use the strcat function to append the spaces but I get compiler errors. I've tried a variety of things, one example of which is shown below. This generates a warning about invalid conversion from 'const char*' to 'char*' in the strcat statement.

void scroll(const char string[], uint16_t displayTime) {
  int fdata;
  int swap;
  char str2[] = "   ";
  strcat(string, str2);

Note that if I don't try to append the three spaces (and therefore don't use the strcat function) it works just fine. Also note that if I don't pass the string to scroll() as a const char, then I get an error attached to the earlier command that calls scroll (from the switch statement).

A workaround would be to just append three blank spaces to the string I want to pass and not use the strcat function, but that seems like cheating to me and I'd like to know how to do this properly.

Thank you in advance.

strcat(char* target, const char* add); is meant to add something to target. Additionally, target has to provide enough space for both the old content of target and the add part.

Something like const char x[] = "part1"; or even a text literal is not suitable as target to strcat, for both reasons.

If you really want to scroll that text along a wider display, I would not consider it "cheating" to add as many spaces as necessary programatically.

(deleted)

but since “TESTING” is a string constant, exactly 8 characters, you can’t append anything to it, there’s no space.

what you could do in your scroll function is allocate a sufficiently long string array, copy the argument into it and then append the spaces

void scroll(const char string[], uint16_t displayTime) {
    char s [40];
    strcpy (s, string);
    strcat (s, "    ");
    ...

OP here

Thank you all so much for the suggestions. After my first post I went outside for some air and while there I thought of something else to try, and when I came back I read this:

what you could do in your scroll function is allocate a sufficiently long string array, copy the argument into it and then append the spaces

Code: [Select] void scroll(const char string[], uint16_t displayTime) { char s [40]; strcpy (s, string); strcat (s, " "); ...

This is what I thought about while outside......I implemented it and there are no compiler errors anymore. Seems so obvious in hindsight, but then, isn't everything?

Thank you again.