CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How do you check the equality of two byte arrays

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
picker



Joined: 07 Sep 2003
Posts: 19
Location: South Africa

View user's profile Send private message

How do you check the equality of two byte arrays
PostPosted: Mon Jan 17, 2005 7:52 am     Reply with quote

I'd like to check whether two arrays are exactly equal (same values in indeces) but the following does not seem to work

byte ONE[5];
byte TWO[5];

.....
....

....

...

if (ONE==TWO)
Success;

This seems to check whether the two have the same address and not the actual values. Do I have to run them through a for loop, is there no other way?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Jan 17, 2005 8:19 am     Reply with quote

Use a loop. If the data is a string, use STRNCMP()
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Jan 17, 2005 8:31 am     Reply with quote

or use: memcmp(ONE, TWO, sizeof(ONE));
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Jan 17, 2005 8:36 am     Reply with quote

oops Embarassed I looked for it in the index of the help file. I didn't see it but do see it listed in the list of standard string functions.
picker



Joined: 07 Sep 2003
Posts: 19
Location: South Africa

View user's profile Send private message

Memcmp doesn't seem to be defined...
PostPosted: Tue Jan 18, 2005 12:54 am     Reply with quote

It doesn't look like memcmp exists, although it shows in the help file.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Jan 18, 2005 2:00 am     Reply with quote

You'll have to include string.h
It is missing from some of the help files, but it is mentioned in the Aug-2004 pdf-fille.
A tip: Study the supplied header files, a lot of goodies can be found there.

Please note that the length parameter is an int8, so a maximum length of 255 can be compared.
picker



Joined: 07 Sep 2003
Posts: 19
Location: South Africa

View user's profile Send private message

Tried it but somehow doesn't work
PostPosted: Tue Jan 18, 2005 2:17 am     Reply with quote

Here's the code , what am I missing?

byte Master[8];
byte buffer[8];
...
...
...
...
...
for (i=0;i<8;i++)
Master[i]=buffer[i];

if (memcmp(buffer,master,sizeof(buffer))==0)
Beep_ok();
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Jan 18, 2005 3:03 am     Reply with quote

Looks fine to me. What is your problem?
picker



Joined: 07 Sep 2003
Posts: 19
Location: South Africa

View user's profile Send private message

It doesn't beep OK
PostPosted: Tue Jan 18, 2005 3:18 am     Reply with quote

No Beep
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Jan 18, 2005 3:42 am     Reply with quote

You didn't mention your compiler version, please do so next time.

I compared string.h v3.187 to v3.216 and it seems they fixed a bug somewhere between those versions.
In memcmp(), change
Code:
char *su1, su2;

to
Code:
char *su1, *su2;
picker



Joined: 07 Sep 2003
Posts: 19
Location: South Africa

View user's profile Send private message

PostPosted: Tue Jan 18, 2005 4:00 am     Reply with quote

Fantastic! Thanks, I'm still running 3.180. I'm too scared to upgrade to a newer version (although I download them) , because everything seems to be working (until I got to memcmp!) and my motto is if its not broken don't fix it...

Thanks for your help ckielstra! Much appreciated...

Regards
Picker
Guest








PostPosted: Tue Jan 18, 2005 2:57 pm     Reply with quote

picker wrote:
Fantastic! Thanks, I'm still running 3.180. I'm too scared to upgrade to a newer version (although I download them) , because everything seems to be working (until I got to memcmp!) and my motto is if its not broken don't fix it...

Thanks for your help ckielstra! Much appreciated...

Regards
Picker


very often it is broken, just you don't know it, until you stumble on a bug.
....
Guest







PostPosted: Tue Jan 18, 2005 4:53 pm     Reply with quote

try visit this link http://ccsinfo.com/forum/viewtopic.php?p=23628&sid=b2a81248802be0631b252a05b677fd18#23628
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group