Questions tagged [memcmp]

memcmp is a function available in the string.h library.

Official Definition

The memcmp() function compares the first n bytes (each interpreted as unsigned char) of the memory areas s1 and s2.

Syntax of usage

#include <string.h>
int memcmp(const void *s1, const void *s2, size_t n);

Source

Linux Man Pages

106 questions
0
votes
3 answers

mem compare arrays to get number of matching bytes

int a[10]; int b[10]; memcmp(a, b, sizeof(int) * 10); memcmp() only tells us which memory block is bigger/smaller since it just returns -1,0,+1. Is there a way to know number of matching elements in a[] and b[] just after which the mismatch…
user1581106
0
votes
3 answers

Read unsigned chars into string

I have an array of unsigned chars: unsigned char buffer[BUFFER_SIZE]; I want to read in the first N unsigned chars from that array into a string however after looking at strncpy(), that seems to only take pointers to signed chars. Should I be…
Patrick
  • 63
  • 3
  • 10
0
votes
4 answers

memcmp with arrays of arrays

In C, I want to check a given array of chars for an arbitrary letter, and change it according to what it is. For example, the characters "a" or "A" would be changed to "4"(the character representing 4). This is a coding excercise for me :) The code…
Sam P
  • 453
  • 6
  • 19
0
votes
1 answer

compare byte[] via pinvoke memcmp combined with multithreading

I wanted to try combining use of memcmp with multithreading there's this code that benchmarked seems to be fastest I've had so far ..but I wanted to check if I could further accelerate the comparison process . thoughts I had : 1) via multithreading…
LoneXcoder
  • 2,121
  • 6
  • 38
  • 76
0
votes
1 answer

C++ memcmp fails with unsigned char array?

I got a probably small problem using memcmp. I have two arrays (length = 3 byte) with exactly the same data. If I try to compare them with memcmp, it fails?! if (memcmp(ucbuffer, ucnewbuffer, buffer.sDeviceData.sLenght)) { cout << "val written,…
AllDayPiano
  • 414
  • 1
  • 4
  • 20
-1
votes
2 answers

unsigned char print correct value like the memcmp

I have this variable, unsigned char identifier1[12]; when I use this identifier is with a cast to const uint8_t* like const uint8_t* getIdentifier() {return identifier1; } and I receive in a function: unsigned char *zid and I want to compare…
JMR
  • 765
  • 1
  • 8
  • 31
-1
votes
1 answer

Where can i find the input values of memcmp (in ARM assembly for reverse engineering)?

First of all, sorry if my english is bad, it is not my natural language. I have no experience in reverse engineering yet. So, i am very confused with my first task in University regarding to this topic. The task is to find a password for a binary.…
Sannin
  • 25
  • 4
-1
votes
1 answer

memcmp from PInvoke in C# doesn't work properly for arrays larger than 4x4

The PInkove part was taken from some SO answer (sorry, I've lost the link to original). Below is the complete program. The output is false. using System; using System.Runtime.InteropServices; namespace Memcpy { class Program { …
Pavel Murygin
  • 2,242
  • 2
  • 18
  • 26
-1
votes
1 answer

Memcpy func take Pointer variable? char *p; char* q; memcpy(p,q,10); will it work?

Memcpy and memcmp function can take a Pointer variable? char *p; char* q; memcpy(p,q,10); //will this work? memcmp(p,q,10); //will this work?
Dev
  • 9
-2
votes
1 answer

C memcmp third parameter type

Third argument in memcmp should be of type sizeof(). I read this code with the following memcmp(st.magic, "outpt_01",sizeof(st.magic)) == 0 && st.version == 0 ) where st is a struct. What is the type of the third parameter in the call above? what…
kiriloff
  • 25,609
  • 37
  • 148
  • 229
-2
votes
3 answers

Does memcmp only work with strings?

If I send memcmp two pointers to integers, then it seems to interpret the integers as chars. For example: int a = 5; int b = 256; int res = memcmp(&a,&b,sizeof(int)); In the code above, it returns 1. I'd like to get a better understanding of this…
-2
votes
1 answer

memcmp strangely fails returning array

I have C++ code that looks like this: static int* ArrayGenerator() { int temp[1] = {9}; return temp; } static int* ArrayGenerator(int i) { //parameter is just for demonstration int temp[1] = {9}; return temp; } int _tmain(int…
happygilmore
  • 3,008
  • 4
  • 23
  • 37
-3
votes
2 answers

Segmentation fault on memcmp

#include #include #include #include int cauta(const void *x, int n, int dim_el, const void *el) { char *c = (char*) x; int i; for(i = 0; i < n; i++) { if(memcmp(c + i * dim_el, el, dim_el) ==…
-3
votes
2 answers

does memcmp work for non-flat struct?

struct Flat { int a1; int a2; } // a hierarchical struct which containing a struct attribute struct NonFlat { Flat b1; int b2; } Flat f1, f2; memcmp (&f1, &f2, sizeof f1) in my compiler, it works, meaning f1.a1 == f2.a1, f1.a2 ==…
pepero
  • 7,095
  • 7
  • 41
  • 72
-4
votes
1 answer

Passing 3rd parameter to memcmp as -1 return 0

For memecmp(), the third parameter is size_t(unsigned). But when we pass third parameter as -1 returns always 0, eventhough the memory block pointed by first and second parameters are different?
geek
  • 47
  • 1
  • 9