Moving/copying a substring for the given string to a different position using memmove() C function

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows 2003 Server Standard Edition

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info:

To do: Copying a substring from a position to the different position in the given string using memmove() C function

To show: How to use memmove() C function to copy a substring to a different position

 

// Using memmove()

#include <stdio.h>

#include <string.h>

 

int main(void)

{

char x[] = "My home is home sweet home";

 

printf(" Using memmove()\n");

printf(" --------------\n");

printf("The string in array x before memmove() is: \n%s", x);

printf("\nThe string in array x after memmove() using \n");

printf("memmove(x, &x[7], 12) is:\n %s\n", memmove(x, &x[7], 12));

return 0;

}

 

Output example:

 

Using memmove()

--------------

The string in array x before memmove() is:

My home is home sweet home

The string in array x after memmove() using

memmove(x, &x[7], 12) is:

is home sweome sweet home

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index