which of the 2 commands are applicable in comparing an array of unsigned chars?
if(strcmp(aAbsC ylNumHigh, bAbsCylNumHigh) <=0 && strcmp(aAbsCylN umLow,bAbsCylNu mLow)<=0 && strcmp(aSecNum, .bSecNum)<0 )
or
if(memcmp(aAbsC ylNumHigh, bAbsCylNumHigh, 2)<=0 && memcmp(aAbsCylN umLow,bAbsCylNu mLow,2)<=0 && memcmp(aSecNum, .bSecNum,2)<0 )
4 14334 Banfa 9,065
Recognized Expert Moderator Expert
The difference is in the third parameter (not there in strcmp).
Basically strcmp assumes you have passed pointers to zero terminated strings and so the compare stops when it finds the first terminator '\0' in either string.
memcmp makes no such assumption so you have to pass it the number of bytes to compare.
In English
strcmp compares 2 arrays of char that contain zero terminated strings
memcmp compares 2 arrays of char that contain any data.
ok i see...
what can you suggest for me to use?
or is it ok to compare using the logical operators in comparing?
sorry sir i am not understanding this mem strcom diffrence
please give me a example
D_C 293
Contributor
Suppose a and b are pointers such that:
*a = 0x68002573
*b = 0x68003673
strcmp(a,b) returns equal because "D" equals "D".
memcmp(a,b,4) returns b > a, since the first and second bytes are the same, but the third byte of b is greater than the third byte of a. The rest of the bytes (just the 4th one) is unnecessary. If memcmp compares the four bytes from both strings, and they are the same, it will return b = a.
With strcmp, it goes until it finds a byte with value 0x00 in either string. You need to pass to memcmp a number of how many bytes to compare. It will compare that many bytes unless there is a difference between respective byte values.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: rajkumar |
last post by:
I have a struct like
struct MyStruct
{
int a;
int b;
int c:
bool d;
bool e;
}
|
by: blueblueblue2005 |
last post by:
hi, I am reading the description of memcmp and strcmp, it seems there
is no big difference between these two functions. except that memcmp
takes void pointer parameters. so why string.h has these two functions
doing the same thing?
|
by: Sidney Cadot |
last post by:
Hi all,
Just browsing through my newly-acquired C99 spec, I was reading on the
memcmp() function (7.21.4.1). It has a rather peculiar wording:
int memcmp(const void *s1, const void *s2, size_t n);
1. The memcmp function compares the first n characters of the object
pointed to by s1 to the first n characters of the object pointed to by s2.
|
by: Alex Stark |
last post by:
Hi,
I'm new to c# an missing functions like memcmp and memcpy from C.
Is there something similar ?
cu
Alex
|
by: Preets |
last post by:
Hi,
Can anybody please tell me the difference between memcmp() and
strncmp() functions ?
| |
by: Sonnich |
last post by:
Hi!
I have 2 arrays which I sort ny the first one.
for($i=0;$i<(count($item1)-1);$i++)
{
$k = $i;
for($j=$i;$j<(count($item1)-1);$j++);
{
if (strcmp($item1,$item1)<0)
|
by: gevadas |
last post by:
sample program
#include <iostream>
#include <vector>
using namespace std;
int find(char*& value,char** arr,int size)
{
for(int i = 0;i < size;i++)
|
by: Martin |
last post by:
Please consider the following code fragment. Assume UINT32 is a typedef
suitable for defining variables of 32 bits, and that ui32 is initialised.
UINT32 ui32;
/* ... */
/* assume ui32 now is holding a value in uc's range */
unsigned char uc = (unsigned char) ui32; /* tell Lint you know target
type is smaller */
cmos->uc = uc;
|
by: jawaraj1911 |
last post by:
Hi all,
Could any help me in which one of following will be efficient,using memcmp() or strcmp() in what way both are good.
Thanks
Jawahar raj R
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |