problem in releasing memory
Any anyone plz help me to figure out why the following code is giving me runtime error in free(pDestn)???
Any help is highly appreciated
1 2 3 4 5 6 7 8 9 10 11 12
|
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *pDestn,*pSource="I Love You Daddy";
pDestn=(char *)malloc(strlen(pSource));
strcpy(pDestn,pSource);
//*(pDestn+16)='\0';
printf("%s",pDestn);
free(pDestn);
//printf("hello");
}
|
pDestn=(char *)malloc(strlen(pSource) + 1);//terminating zero
Last edited on
Topic archived. No new replies allowed.