strings.h strncmp returs always a zero

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
ondrej_bajer
Posts: 32
Joined: 17 May 2018 09:55

strings.h strncmp returs always a zero

Post by ondrej_bajer » 10 Aug 2018 21:46

Hi guys,

I want to use strncmp function in order to compare start of two chararrays. But it returns me zero in every case. What am I doing wrong, please?
Test sketch here:

Code: Select all

void setup() {
   Serial.begin (9600);
}

#include <string.h>

char CharBuffer[50] = "123456789ABC";
char CompareBuffer[50] = "123456789XXX";
word NumberOfToCompare;
int Result;

void loop () {
  
  NumberOfToCompare = 5;
  Result = strncmp (CharBuffer, CompareBuffer, NumberOfToCompare);
  Serial.println(Result);

  NumberOfToCompare = 11;
  Result = strncmp (CharBuffer, CompareBuffer, NumberOfToCompare);
  Serial.println(Result);
  
  NumberOfToCompare = 12;
  Result = strncmp (CharBuffer, CompareBuffer, NumberOfToCompare);
  Serial.println(Result);
  
  delay(1000);
 }

Post Reply