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

How to add array in multidimensional array?

My question is very simple, but I still can't manage to get things right because I am simply not used to the C language. I have an array that looks like this: char *itemArr[] = { "GPGGA", "193914.00", "5312.983745", "N", …
Aerial
  • 1,185
  • 4
  • 20
  • 42
-1
votes
1 answer

Cuda issue on converting image to grayscale

I am having an issue with the following code. The following code takes an input image and it should save the grayscale of it. Unfortunately, it seems to perform the expected behavior but it is processing just a part of the image and not the whole.…
Michalis
  • 3
  • 7
-1
votes
2 answers

C - Memcpy not working

First, know how memcpy work: the third parameter is the number of bytes copied, however, i still have a problem ... Here's my struct: #define ARRONDI(X, Y) 1 + (X / (Y + 1)) #define Taille ARRONDI(Max_Length, 64) #define Max_D 7 typedef unsigned…
Viridya
  • 640
  • 5
  • 13
-1
votes
3 answers

Remove characters from string in C

I'm having an issue removing characters from a string. I have been able to identify the characters to remove and store them as a new string but I would like a code that enables me to remove the new string's characters from the original string (where…
-1
votes
2 answers

C copy file with memcpy and mmap file to RAM

I have file1.txt This is my file and file2.txt This is my second file and I want copy file2.txt content to file1.txt using memcpy int main( int argc, char * argv[] ){ int d; int d2; int p; FILE *f1; FILE *f2; if(argc ==…
David
  • 3,055
  • 4
  • 30
  • 73
-1
votes
1 answer

memcopy uint16_t to char* for UDP transport

I've been working on a UDP reliable transport in C. I have a struct with the following format: struct packet { uint16_t cksum; /* Ack and Data */ uint16_t len; /* Ack and Data */ uint32_t ackno; /* Ack and Data */ uint32_t seqno; /* Data…
JHenry
  • 1
-1
votes
1 answer

memcpy_ssse3 segmentation fault

SIZE = 2*1024*1024*1024; struct { char array[SIZE]; } s1; char *seq; File *sp; int i = 0; EoFReached = 0; memset(array,0,SIZE*sizeof(char)); while(EoFReached == 0) { getseq(sp, seq, EoFReached); memcpy(&(s1->array[i]),seq, seqlen); i…
bsp
  • 1
  • 1
  • 3
-1
votes
1 answer

double free or corruption error on free

this is the piece of code i use to create my char array on heap int currentArraySize = 10; char **finalArray = malloc(sizeof(char*)*currentArraySize); char buf[6] = "hello"; for(int b=0; b
epipav
  • 339
  • 2
  • 14
-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
-1
votes
1 answer

floating point precision using memcpy C++

I have a tricky problem that I do not understand. I have an array of uint8_t that I need to convert to a 32 bit floating point. I am using memcpy to accomplish that...however the rounding seems to be off. Could someone please explain what is…
-1
votes
2 answers

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] c programming

I don't understand why this warning is triggered! test.c:920:56: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] if((memcpy((void *)(buffer_post_offset + position), (void *) data_block_n, bytes_to_write)) ==…
-1
votes
1 answer

opposite of memcpy to go from binary to text

I am looking for a method that will do the opposite of memcpy when I make a copy of a buffer. For example, if I had this code _memccpy(szbuffer, buffer, BUFFER_SIZE, 0); The result of szbuffer is then binary. If I send this over from a socket to a…
VMA92
  • 469
  • 2
  • 8
  • 19
-1
votes
4 answers

strcpy vs memcpy for copying char * with known size

I don't care about the NULL terminator so I have two choices: strcpy(createTabStmt, "CREATE TABLE "); //shorter and more readable code Or memcpy(createTabStmt, "CREATE TABLE ", sizeof ("CREATE TABLE ") - 1); //faster? Is the memcpy version always…
cshu
  • 5,654
  • 28
  • 44
-1
votes
2 answers

Modify String Data

I want to substring and modify my string (which is defined below). char gps[]="$GPGGA,115726.562,4512.9580,N,03033.0412,E,1,09,0,9,300,M,0,M,,*6E"; Shortly, I want to take and increase Lat,Long data which means My steps Take lat info as char or…
-1
votes
2 answers

assigning casted pointer or memcpy

Assuming memory to be perfectly aligned for the operation and T to be a basic type (int, float, double, ect), which of these operations would be more efficient on most compilers at maximum optimization level? : void *memory = ::operator…
RamblingMad
  • 5,332
  • 2
  • 24
  • 48