Passing String Values from Bridge to a Function [SOLVED]

I started to write multiple function (subroutines?) to clean up a lot of repetitive code and I've had a great deal of success, but I can't seem to get a string of text to pass through to a function. I have a feeling that it's because of a mismatch in the type of character string that gets passed, but I keep hitting a wall.

At the moment, I am receiving a constantly changing variable from the Bridge using:

char c_weather[20];

Bridge.get("c_weather", c_weather, 20);

The weather variable includes text like "Clear", "Chance of Thunderstorms", "Snow", etc., so it will change in length.

I was able to compare the string value to specific text within the void loop using this:

 if (strcmp(c_weather, "Clear") == 0) {
    strip.setPixelColor(10, 255, 255, 0);

But now I can't seem to pass the code through a separate function using this code:

Conditions (c_weather[20]);

void Conditions (char c[20]) {
  //Get Current Condition Icon
  if (strcmp(c, "Clear") == 0) {
    strip.setPixelColor(10, 255, 255, 0);}

The program error indicates "an invalid conversion from 'char' to 'char*'"

Once again, I'm lost on the different character and string types and this is the last piece of my puzzle. I could get by with everything remaining in the void loop, but that seems like poor coding and a waste of program space.

Thanks for any help!

Conditions (c_weather[20]);

You are passing the 21st element of a 20 element array to a function that expects an array.


is the proper way to pass the array to the function.

Thanks PaulS, but when I pass it like you mentioned, I get a litany of errors:

Small_Test:98: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:25:0,
                 from C:\Program Files (x86)\Arduino\libraries\Bridge\src/Bridge.h:26,
                 from C:\Program Files (x86)\Arduino\libraries\Bridge\src/Process.h:22,
                 from Small_Test.ino:1:
c:\program files (x86)\arduino\hardware\tools\avr\avr\include\string.h:125:12: error:   
initializing argument 1 of 'int strcmp(const char*, const char*)' [-fpermissive]
 extern int strcmp(const char *, const char *) __ATTR_PURE__;

Which I assume is because of a mismatch with the "strcmp" command that I'm using in the function. The syntax works in void loop, but not in its own function.

Change Conditions() to expect a char *.

void Conditions (char *c)

Ha! Yes! Thank you so much! Over 8 hours of pulling my hair out and it works! What a relief!

You might also see this written elsewhere as:

void Conditions (char c[])

The two are equivalent. This is essentially telling the function that "you are receiving an array of characters named c." Because an array name equates to the starting memory address of the array, it's the same as passing a pointer to the array, which is what Paul showed you.

Thanks econjack! I must have tried 20 different variations, but never quite got the right syntax.