user23365: I am not actually using ad arduino but an atmel chip. but my question is c microprocessor related
I am reading an uart which returns data in the form uint8_t [100]
I can print the  return just fine, the return is "OK"
but when I try to use strcmp(read, "OK")
I do not get the expected value, I get a mismatch ( strcmp returns 13, not 0)
uint8_t  sigfox_rd_buf[100] = {0};
uint8_t sig_rd = 0;

io_sigfox->read(io_sigfox,&sig_rd, 1);
while(sig_rd != 10) // read until end char
 {
     sigfox_rd_buf[i] = sig_rd;
     i++;
     io_sigfox->read(io_sigfox,&sig_rd, 1);
 }
 if(strcmp((char *)sigfox_rd_buf,"OK") == 0 )
 {
  do_something()
 }
 else
{
complain();
}

and I always end up in complain for some reason.. please help!! :)

user20245: When using strcmp(), strings should be terminated with a NULL character.  Which, by the way, is a zero. Your code should work as is if you replace the Line Feed character (10 or 0x0a) with a NULL (0 or 0x00). That is assuming the string you are getting back is 0x4f, 0x4b & 0x0a.  Or you could play it safe and replace strcmp with strncmp.  Then explicitly state the number of characters to compare:
if(strncmp((char *)sigfox_rd_buf,"OK",2) == 0 )


23365: <p>I am not actually using ad arduino but an atmel chip. but my question is c microprocessor related</p>

<p>I am reading an uart which returns data in the form uint8_t [100]
I can print the  return just fine, the return is "OK"</p>

<p>but when I try to use strcmp(read, "OK")
I do not get the expected value, I get a mismatch ( strcmp returns 13, not 0)</p>

<pre><code>uint8_t  sigfox_rd_buf[100] = {0};
uint8_t sig_rd = 0;

io_sigfox-&gt;read(io_sigfox,&amp;sig_rd, 1);
while(sig_rd != 10) // read until end char
 {
     sigfox_rd_buf[i] = sig_rd;
     i++;
     io_sigfox-&gt;read(io_sigfox,&amp;sig_rd, 1);
 }
 if(strcmp((char *)sigfox_rd_buf,"OK") == 0 )
 {
  do_something()
 }
 else
{
complain();
}
</code></pre>

<p>and I always end up in complain for some reason.. please help!! :)</p>
 20245: <p>When using strcmp(), strings should be terminated with a NULL character.  Which, by the way, is a zero. Your code should work as is if you replace the Line Feed character (10 or 0x0a) with a NULL (0 or 0x00). That is assuming the string you are getting back is 0x4f, 0x4b &amp; 0x0a.  Or you could play it safe and replace <a href="http://linux.die.net/man/3/strncmp" rel="nofollow">strcmp with strncmp</a>.  Then explicitly state the number of characters to compare:</p>

<pre><code>if(strncmp((char *)sigfox_rd_buf,"OK",2) == 0 )
</code></pre>
