Data type mismatch in strcmp()


greetings,

i trying code weather station upload data server -- sparkfun.data.com @ moment -- via http on adafruit fona module. fona acts cell phone modem, taking @ commands , returning various items of data in response, including ok , error messages. trying code function compare responses fona expected string pass function (for example, "ok"), sketch can, example, retry connection if fails. fona libraries offer functions control not granular like.

the function's code follows:

code: [select]
string fonaparse(string reply)
{
char buffer[50];
string content = "";
  char character;
 
  delay(1000);

  while(fona.available() > 0) {
      character = fona.read();
      content.concat(character);
  }

  if (content != "") {
  content = string(content);
  serial.println(content);
    if(strcmp(content, reply) == 0)
    {
    serial.println(f("acknowledged."));};
    if(strcmp(content, reply) == 1)
    {
    serial.println(f("failed."));};
  }

}


if comment out lines "if(strcmp(content, reply) == 1)" onward, expected strings ("ok") on serial. if uncomment these, get:

code: [select]
  report have more information with
sketch_jan14a.ino: in function 'string fonaparse(string)':
sketch_jan14a:598: error: cannot convert 'string' 'const char*' argument '1' 'int strcmp(const char*, const char*)'
sketch_jan14a:601: error: cannot convert 'string' 'const char*' argument '1' 'int strcmp(const char*, const char*)'


this confuses me because doesn't me i've used const char* type of variables involved. inserted "content = string(content);" in hopes cast data in such way satisfy compiler, same errors line without it.

i hope can clarify misunderstanding. many thanks.

strcmp takes 2 character arrays arguement, not strings.  string class object, not character array.  since appears comparing 2 strings, should able use content.equals(reply) instead.

regards,
ray l.


Arduino Forum > Using Arduino > Programming Questions > Data type mismatch in strcmp()


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code