A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/c_standard_library/c_function_memmove.htm below:

C library - memmove() function

C library - memmove() function

The C library memchr() function is used to copy a block memory from one location to another. Typically, this function state the count bytes of data from a source location to the destination.

Syntax

Following is the syntax of the C library memchr() method −

void *memmove(void *dest_str, const void *src_str, size_t numBytes)
Parameters

This function accepts the following parameters

Return Value

This function returns a pointer to the destination i.e *dest_str.

Example 1

Following is the basic C library function memchr() to change the postion of strings.

#include <stdio.h>
#include <string.h>

int main () {
   char dest_str[] = "oldstring";
   const char src_str[]  = "newstring";
   printf("Before memmove dest = %s, src = %s\n", dest_str, src_str);
   memmove(dest_str, src_str, 9);
   printf("After memmove dest = %s, src = %s\n", dest_str, src_str);
   return(0);
}
Output

The above code produces the following output−

Before memmove dest = oldstring, src = newstring
After memmove dest = newstring, src = newstring
Example 2

In the below example, we use the puts() method for the destination string. This method add the string with a newline character and returns an integer value. When copying the content from the source string to the destination, we utilize the memmove() method.

#include <stdio.h> 
#include <string.h> 

int main() 
{ 
	char dest_str[] = "Tutorialspoint"; 
	char src_str[] = "Tutors";

	puts("source string [src_str] before memmove:-"); 
	puts(dest_str); 

	/* Copies contents from source to destination */
	memmove(dest_str, src_str, sizeof(src_str)); 

	puts("\nsource string [src_str] after memmove:-"); 
	puts(dest_str); 
	return 0; 
}
Output

On executing the above code, we get the following output−

Source string [src_str] before memmove:-
Tutorialspoint

Source string [src_str] after memmove:-
Tutors

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4