Okay, I have been trying for hours to get this to work, and I made it quite a ways on my own, but this last little bit has me stumped.
Basically, I need to test two strings to see if they match, and use that in an "if" statement.
What I've got now is:
if (InputValueC == Input10)
I've also tried these two:
if ('InputValueC' == 'Input10')
if ((InputValueC) == (Input10))
Monitoring the Software Serial "print" command, I can see that both of these strings are the same. But, it does not execute the code following the "if" statement.
The syntax for the "if" statement I'm using (as far as I can tell) is correct:
if (test)
{
run
these
commands
}
else
{
run
these
other
commands
}
You need to use the strcmp() function, if both stings are equal then strcmp(string1, string2) == 0.
You can also use strcasecmp() to compare them without regard to case.
Now, it works for most of it, but not part of it. I'm not sure why, though, but I do have a theory.
Is is possible to change a string within the loop, but after it was already declared (before the loop)? If so, then I'm doing something wrong. I'm using "char" both places. Before the loop starts, I have this code:
Printing to the serial was my debugging technique, to see where the problem was. Considering that it prints "LightsWillNotShow" on the serial line, I figured it had something to do with the "char" statements.
Is it possibly because of the extra whitespace? I've always read that this didn't matter, but I am not the one to answer this question; I have extremely little programming knowledge.
@peter247:
I just now saw your response. I looked at that page, and I do not understand it. Also, when I first tried putting this code at the top of the sketch:
#include <string.h>
It gave some error about not being able to find it/it not existing. However, after trying it again just now, it compiles without errors.
(Yet, I still do not understand the code on the page you linked to. Major newbie here. ;))
Would this replace the contents of the string "LightState" with the contents of the string "LightState1"
Yes, assuming you had already declared those strings and given them reasonable ASCII contents. But be careful, because 'strcpy' does not check the length of the strings in any way. If the new contents (LightState1) are longer (more characters) than the space you've allocated in the destination string (LightState), then you will overwrite memory somewhere. Most likely somewhere bad!
Remember to allow room in the strings for the terminating zero byte: