Questions tagged [memmove]

memmove() is a C standard library function to copy a block of memory. It work even if the source and the destination overlap.

144 questions
1
vote
3 answers

Memmove in same pointer for deleting multiple whitespaces C

while this Code works: char * k = "asd"; char * j = malloc(sizeof(char) * 3); memmove(j,k,3); printf("%s",j); while code gives error: char * k = "asd"; char * j = malloc(sizeof(char) * 3); memmove(k,k+1,3); printf("%s",k); // output should…
Batuhan Yaman
  • 25
  • 1
  • 1
  • 5
1
vote
1 answer

malloc, free, and memmove inside a subfunction

I want to use a subfunction to copy a char array. it is like this: void NSV_String_Copy (char *Source, char *Destination) { int len = strlen(Source); if (*Destination != NULL) free(Destination); Destination = malloc(len + 1); …
CaTx
  • 1,421
  • 4
  • 21
  • 42
1
vote
2 answers

How to split a generic void array into parts.c

as a beginner in C, I am struggling with an obscure problem and because I couldn't find a solution to this particular problem I want to ask you the following: Currently I am trying to understand void pointers and their arithmetic operations. I…
matzui
  • 17
  • 3
1
vote
6 answers

concatenate strings with memmove() in function

I want to concatenate two strings using a function that returns the resulting string. it would be something like this: char *String_Concat (char *String_1, char *String_2) { char *StringResult; //memmove String_1 to StringResult …
CaTx
  • 1,421
  • 4
  • 21
  • 42
1
vote
1 answer

Referencing memory that is overwritten by a memmove

I have the following code: int** x; // Add 4 int pointers to x - code ommitted // Pop the first element int* a = x[0]; memmove(&x[0], &x[1], sizeof(int*) * 3); x = realloc(x, sizeof(int*) * 3); // Some code that uses 'a' - ommitted As per my…
thameera
  • 9,168
  • 9
  • 37
  • 38
1
vote
1 answer

Is there an equivalent of C++ std::copy in Rust?

The std::copy function in C++ copies elements pointed at by one iterator over the elements pointed at by another iterator. One important aspect of std::copy in C++ is that good implementations optimize by using std::memmove if the type of the…
kmky
  • 783
  • 6
  • 17
1
vote
2 answers

What is memmove() alternative when I know the overlapping side?

I want know what the fastest function for copy n bytes from *source to *destination, when *destination = *source + k, and k is netural or zero. The memcpy() function has undefind behavior for overlapping. The memmove() function is not the best,…
user1134316
1
vote
1 answer

Problems with Memmove and SIGSEGV in C

I am having some issues with a memmove in C. As far as I can tell, both locations are valid memory addresses, I am able to print the contents of both memory locations before I perform the memmove, however as soon as I attempt to memmove, the…
paged90
  • 21
  • 3
1
vote
4 answers

Why can't I memmove std::string?

#include #include #include using std::string; string *arr_ptr; int capacity; void add() { int old_capacity = capacity; capacity <<= 1; // double the capacity string *tmp_ptr = new string[capacity]; …
Determinant
  • 3,886
  • 7
  • 31
  • 47
1
vote
1 answer

memove a masked array - python

I have a numpy array which contains no data values. I mask those no data values so that they do not influence my calculations using: array = numpy.ma.masked_values(array, options['ndv'], copy=False) I then use memmove to get the numpy array…
Jzl5325
  • 3,898
  • 8
  • 42
  • 62
0
votes
2 answers

Is there an "lseek" to memmove?

I have a buffer with n bytes, but I only want read in sizeof(something) bytes from byte 3, meaning I don't want to read in byte 1 and 2 from the buffer. For example... For some buffer, byte 1 = 'a', byte 2 = 'b', byte 3 = uint64_t variable. What I…
Kobi
  • 1,395
  • 4
  • 17
  • 23
0
votes
1 answer

Can memmove accessing the contents of a FILE* and delete information?

Does memmove work on file pointer data? I am trying to remove a line from a C file. I am trying to use memmove to make this more efficient than the internet's recommendation to create a duplicate file and overwrite it. I have debugged and I can't…
sasukenebe
  • 21
  • 3
0
votes
2 answers

Replacing a substring with another string in C

I am writing a code to replace all MACROS with its value. If my macro MAX has a value 1000, And in the code, it must be replaced with 1000.(I am assuming a case that if the MACROS are the first word in a line, then in that line MACROS will not we…
Muthu Ganapathy Nathan
  • 3,199
  • 16
  • 47
  • 77
0
votes
1 answer

How to remove the first string element in array of string

Assuming I have this array of string char* arr[] = {"Me", "you", "Now", NULL}; My aim is to remove "Me" so that the resultant array is: arr = {"you", "Now", NULL}; Is there a way I can do this without running a for loop and store the element in a…
Pac
  • 3
  • 2
  • 5
0
votes
1 answer

Problem of "cyclic data " in x86_64 assembly code

I'm trying to write memmove in assembly: the problem is that in my section data I've got two line : source and destination, and when I'm trying to pass 20 byte from source to destination while source got just 15 byte the 16th byte that pass from…