Questions tagged [memcpy]

memcpy() is a C standard library function used for copying a block of memory bytes from one place to another.

Synopsis

#include <string.h>

void *memcpy(void * restrict s1,
     const void * restrict s2,
     size_t n);

Description
The memcpy function copies n characters from the object pointed to by s2 into the object pointed to by s1. If copying takes place between objects that overlap, the behavior is undefined.

Returns
The memcpy function returns the value of s1.

1578 questions
-1
votes
2 answers

Efficient way to reorganize data in a buffer in C++

Let's say I have a unsigned char buffer that looks like this: unsigned char buffer = {'A', 'B', 'C', 'A', 'B', 'C', 'A', 'B', 'C', 'A', 'B', 'C'} Basically I just want to grab that A's and B's, and pack them into a new buffer like this: unsigned…
Bobby Pardridge
  • 267
  • 6
  • 16
-1
votes
1 answer

memcpy extra starting characters

I'm having some trouble using memcpy in that when the memcpy operation is performed I get: "ÍÍWF03-021913.datýýýý««««««««þ" when I should get: "WF03-021913.datýýýý««««««««þ" I don't know where these leading "ÍÍ" are coming from. Code: note:…
Lou_257
  • 331
  • 1
  • 2
  • 7
-1
votes
1 answer

u_char* memcpy segfault -- tried other answers

I have a u_char array, which changes each time I enter the loop, and a structure with a member as a u_char array. I am trying to create a vector of structures, containing all iterations of the u_char array. But I get either a segfault (when I use…
ROARK
  • 61
  • 1
  • 4
-1
votes
1 answer

Issue with memcpy and bad access

First time asking a question here, but I'm really confused by this. This is essentially what I'm trying to do: - (MyStruct)methodName:(OtherStruct)foo { MyStruct bar; memcpy(&bar, &foo, sizeof(MyStruct)); return bar; } My attempts to…
Tyler
  • 13
  • 3
-1
votes
1 answer

compare two vectors in c++ with template class

I want to compare two vectors using template class. vector gExpMsg; vector gRevcMsg; i have to use template class; and compare 2 vector using memcmp. Could you please guide me in code C++. Thanks in Advance.
-1
votes
1 answer

memcpy() with different data types

Trying to copy A into B.... char *A; double *B; unsigned int size = 1024; A = malloc (size*size * sizeof (char)); B = malloc (size*size * sizeof (double)); //fill A here memcpy (B, &A[0], (size*size * sizeof (char))); Printing values in B don't…
RHok
  • 152
  • 1
  • 2
  • 11
-1
votes
1 answer

memcpy implementation issue

I am writing a small implementation of memcpy as follows. #include "stdio.h" int main( ) { int i=5; int j=4; printf("i=%d\t",i); swap(&i,&j,sizeof(int)); printf("i=%d",i); return 0; } int swap(void *vp1,void *vp2,int…
Vaibhav Sundriyal
  • 567
  • 5
  • 11
  • 18
-1
votes
2 answers

How to store int in char * in iphone

Can anyone help converting the Int to char array as i have buffer as char *buffer = NULL; int lengthOfComponent = -1; char *obj; buffer[index]= (char *)&lengthOfComponent; if i do this it is thorwing EXCESS BAD ACCESS after the execution how…
012346
  • 199
  • 1
  • 4
  • 23
-1
votes
1 answer

memcpy uint32_t and char* into char*

this doesnt works for me: char buff[11]; char* msg_ptr; msg_ptr = buff; uint8_t id; uint32_t msg_length; char msg[] = "hallo"; id = 77; msg_length = 5; memcpy(buff, &id, sizeof(uint8_t)); memcpy(buff+1, &msg_length,…
user1324258
  • 561
  • 2
  • 8
  • 25
-2
votes
4 answers

Garbage value when swapping array with memcpy()

I am trying to make a generic swap function using memcpy() in C. I am getting a garbage value when I try to swap arrays. This is code below: #include #include typedef struct Student { char a[10]; int b; double c; } …
-2
votes
1 answer

memcmp on a zero length array got array-bounds error

There is a main.c file, whose content is: #include "memory.h" #include "stdint.h" #define MOLECULE_API_DECORATOR MOLECULE_API_DECORATOR const uint8_t MolDefault_ByteOpt[0] = {}; int main(int argc, char *argv[]) { uint32_t size =…
Eval EXEC
  • 1
  • 1
-2
votes
1 answer

struct memcpy vs assignment in C++

I'm reading a book "Multiplayer games. Development of network applications" by Joshua Glazer and Sanjay Madhav. class SocketAddress { public: SocketAddress(const sockaddr& inSockAddr) { memcpy(&mSockAddr, &inSockAddr, sizeof(sockaddr)); …
-2
votes
1 answer

C function to memcpy part of the array to another reallocated part of the array

I need to take a part of an Array, let's say: 32 64 66 69 72 78 81 87 94 95 1 2 4 8 16 realloc a new memory from the end of the array, take the part from 32 to 95 using memcpy to copy it after 16, rearrange the array and return the value of k (k is…
-2
votes
5 answers

Need help in coping buffer using memcpy

in the following code when i use fwrite its giving correct o/p. While memcpy is not working. typedef struct { char *p1; char *p2; } node; char s[] = "hello"; char t[] =" there"; node t1, t2; char str; FILE op_f; t1.p1 =…
arccc
  • 17
  • 5
-2
votes
1 answer

Using memcpy to copy a range of elements from an 2d array

Say we have two 2d arrays: double matrix [64][100]; double array[64][32]; And we want to copy 32 elements from matrix[64][50:82] to array[64][32] using memcpy. Do you the solution?
1 2 3
99
100