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
3 answers

How can I copy 4 letter ascii word to buffer in C?

I am trying to copy the word: 0x0FF0 to a buffer but unable to do so. Here is my code: #include #include #include #include #include #include #include #include…
David8988
  • 79
  • 1
  • 1
  • 7
-1
votes
2 answers

memcpy(), uninitialized local variable

Initially, i ran this code on ubuntu and it worked just fine without any warnings whatsoever. However, when I run it on VS on windows it says _operand1 is not initialized. I'm wondering how it can go wrong. I know about not casting results of…
pr12015
  • 67
  • 7
-1
votes
2 answers

Converting std::copy to std::memcpy is not working?

I have function which copies of array of integer into vector which is working fine with std::copy call but when I changed std::copy to std::memcpy its not working correctly. Can someone plz point out what I am doing wrong ? void…
-1
votes
1 answer

How do I properly use memcpy without getting seg faults?

I'm currently working on a huffman coding program. I have a file named huffencode.c, that is then linked through a header through what works as my main function encodeFile() down below. The below function makeCodes() is giving me a Seg fault at the…
tris
  • 49
  • 7
-1
votes
1 answer

Segfault in parsing char* into tokens

I'm trying to parse a string around an arbitrary index. In my simplest test program I could come up with I have an input string I read the input into and then do memcpy to parse the string. For testing this I am typing in "this text" as input.…
Yoink
  • 167
  • 2
  • 11
-1
votes
5 answers

Avoiding memset for a multi-type structure

I would like to avoid using memset() on a structure like this: typedef struct { int size; float param1; } StructA; typedef struct { StructA a; unsigned int state; float param2; } Object; Can I do something like this (pseudo…
alpereira7
  • 1,522
  • 3
  • 17
  • 30
-1
votes
4 answers

"memcopy" style construction of an object in C++

In certain embedded situations, memory needs to be moved with memcopy style functions (such as from external memory, or using closed API calls). When such a C++ object needs to be moved this way, however it doesn't have a default constructor, you…
Andrew Spott
  • 3,457
  • 8
  • 33
  • 59
-1
votes
1 answer

Why memcpy performance deteriorates when used in multible threads?

I wrote a short test program on Linux to test how memcpy performs when used in multiple threads. I didn't expect it to be as devastating. Execution time went from 3.8 seconds to over 2 minutes while running two instances of the program concurrently…
Andreas
  • 177
  • 1
  • 8
-1
votes
1 answer

why this C code is crashing

#include #include void *mymemmove(const char *str1,const char* str2,int n) { char *tmp = (char*)malloc(sizeof(char)*n); memcpy(tmp,str2,n); memcpy(str1,tmp,n); free(tmp); return NULL; } int main(void) { …
-1
votes
1 answer

I need to copy in reverse manner an array of longs I need a system function such as memcpy is there any?

I need to copy from end to start an array of longs to an array of longs as is shown in the code bellow. Is there any function similar to memcpy for the required purpose ? typedef long int myT; const size_t n=5; myT a[n]; myT…
George Kourtis
  • 2,381
  • 3
  • 18
  • 28
-1
votes
2 answers

memcpy erase variables in char array in C

I create multi dimensioanl array and write it to console char a[5][10]; strcpy(a[0], "111111"); strcpy(a[1], "211112"); strcpy(a[2], "311113"); strcpy(a[3], "411114"); strcpy(a[4], "511115"); printf("size : %d \n", sizeof(a)); int i; for(i = 0;…
utarid
  • 1,642
  • 4
  • 24
  • 38
-1
votes
1 answer

Not quite sure, segfault on memcpy?

I'm having some trouble with memcpy throwing a segmentation fault, and I can't seem to locate the source of the error. typedef struct { int record_code; char* record_name; char buffer[6004]; }…
ottocay
  • 29
  • 2
-1
votes
1 answer

memcpy gives me weird results with struct

In a project, I was asked to create an INT128 type using int32_t and make postfixed calculations with them. I was using a generic stack to keep track of the operands. The code is below: typedef struct int128 { int32_t byteArray[4]; }…
Lincoln Alves
  • 546
  • 5
  • 13
-1
votes
2 answers

Dereferencing an out of bound pointer that contains the address of an object (array of array)

Is the following well defined, for different values of REF? #include #define REF 1 #define S 1 int main(void) { int a[2][S] = {{1},{2}}; int *q = REF ? a[1] : 0; int *p = a[0] + S; memcpy (&q, &p, sizeof q); printf…
curiousguy
  • 8,038
  • 2
  • 40
  • 58
-1
votes
1 answer

C : Insert/get element in/from void array

I have to create a generic array that can contain generic data structures. How can i put a generic structure into an empty slot of my void array? This is my code. struct CircularBuffer { int E; int S; int length; // total number of…
Simon
  • 95
  • 1
  • 11