[Solved] How to do this instead of a function parameter...

Hello,

Sorry for title, I couldn't find the right words...

So I have this thing:

const char COMMAND_CHARACTER = '/';
...
if ( input[0] == COMMAND_CHARACTER )
{
  if ( !strcmp( input+1, "toggle" ) )
  ...

So "/toggle" is a command.

I just would like to know, if it's possible, how to replace the "input+1" in the strcmp, by simply "input", something like this:

  input += 1; // I know this is wrong, but what to put here? 
  if ( !strcmp( input, "toggle" ) )

So I don't have to put +1 in each commands...

Thanks!

Depends. How was input defined, as an array (answer is NO), or as a pointer (answer is YES)?

You are using strcmp to compare two things that are not strings. Do you think that is going to work?

liudr: Depends. How was input defined, as an array (answer is NO), or as a pointer (answer is YES)?

input is defined as a char array, it's used to store the characters received by Serial.read(). So it isn't possible? :'(

Grumpy_Mike: You are using strcmp to compare two things that are not strings. Do you think that is going to work?

I don't understand. It's working perfectly actually :)

PS: I know I could shift everything in input of 1 to the left, but I would like to avoid doing this...

What's wrong with incrementing input?

If you're that upset by arithmetic, why not use a macro?

  if ( !strcmp( &input [1], "toggle" ) )

That should do it.

Arrch: What's wrong with incrementing input?

Nothing really, I just find it ugly to have to do this for every commands!

[quote author=Nick Gammon link=topic=134032.msg1008343#msg1008343 date=1353796202]

  if ( !strcmp( &input [1], "toggle" ) )

That should do it. [/quote]

This also work, but same, I can't put it outside of the function call (I think).

I think I solved it...

 char *command = input+1;
 if ( !strcmp( command, "toggle" ) )

I was about to suggest the pointer solution but you figured it out by yourself. Good for you. FYI, you can't increment array name as they are equivalent to constant pointers so no change is allowed.

liudr: FYI, you can't increment array name as they are equivalent to constant pointers so no change is allowed.

Thank you that's what I was wondering :)

You are welcome. Pointers are wonderful abstracts of C, source of much inspiration and frustration.