Using STRNCMP

Hi, I am using STRNCMP to test for a new minute, but I am getting somewhat inconsistent results occasionally. Here's the relevant code:

...

char *sTemp=new char [10];

sTemp2=Datasource->NewTimeStamp; //Read the new timestamp from datasource
substring(sTemp2,sTemp,3,2); //Extract the current minute

if(strcmp(sTemp,baseInfo[i][1])!=0) {
// New Minute

// Save current time
baseInfo[i][1]=sTemp;

// Do something
...

}

This works mostly fine, but I get some occasionally intra-min data which slips through the if() statement. I think it's because the substring function does not append a eol? Any suggestion as to the best way to check for a new minute?

Thanks
you're not using strncmp but strcmp which needs a 0 at the end which I guess you don't provide. Better use std::string for tasks like that
Topic archived. No new replies allowed.