1: #include <stdio.h>
2: #include <string.h>
3: void * my_memmove(char *dest,char *src,int count)
4: {
5: char *temp;
6: char *s;
7: if ( dest <= src) {
8: temp = dest;
9: s = src;
10: while(count--)
11: *temp++ = *s++;
12: } else {
13: temp = dest;
14: temp += count;
15: s = src;
16: s += count;
17: while(count--)
18: *--temp = *--s;
19: }
20: return dest;
21: }
22: main()
23: {
24: char str[100] = "abcdefghijklmnopqrstuvwxyz";
25: my_memmove(str+5,str,4);
26: printf("my_memmove = %s\n",str);
27: strcpy(str,"abcdefghijklmnopqrstuvwxyz");
28: memmove(str+5,str,4);
29: printf("sys_memmove = %s\n",str); // compare with original memmove
30: strcpy(str,"abcdefghijklmnopqrstuvwxyz");
31: memcpy(str+5,str,4);
32: printf("sys_memcpy = %s\n",str); // and memcpy to check overlap
33: }
RTOS, Linux Kernel internal, OS-Programming C & Data Structures, Debugging, Optimizations, Makefiles and Wireless Technologies (Wi-Fi ,LTE and LTE-Advanced )
Search This Blog
Wednesday, October 28, 2015
write your own memmove program without overlapping constrain.
Labels:
C
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment