#include <stdio.h>
#include<stdlib.h>
void *mymemmove(const char *str1,const char* str2,int n)
{
char *tmp = (char*)malloc(sizeof(char)*n);
memcpy(tmp,str2,n);
memcpy(str1,tmp,n);
free(tmp);
return NULL;
}
int main(void) {
// your code goes here
char *p1,*p2,*p3,*p4;
//p1= (char *)malloc(sizeof(char)*30);
p1="ankitagrawal";
p2=p1+2;
char *tmp = (char*)malloc(sizeof(char)*13);
memcpy(tmp,p1,13);
memcpy(p2,tmp,13);
printf("p1 = %s /n p2= %s tmp =%s",p1,p2,tmp);
//mymemmove(p2,p1,13);
//printf("p1 = %s /n p2= %s",p1,p2);
return 0;
}
My code is crashing in the second memcpy in the main function . can anyone please tell me what is the problem with the code ?