char *a=NULL;
char *s=NULL;
a=(char *)calloc(1,(sizeof(char)));
s=(char *)calloc(1,(sizeof(char)));
a="DATA";
memcpy(s,a,(strlen(a)));
printf("%s",s);
Can you plz tell me why its printing DATA½½½½½½½½■ε■????How to print only DATA?? Thanks
strlen does only count the chars without the terminator ‘\0’.
Without this terminator printf does not know the end od the string.
Solution:
memcpy(s,a,(strlen(a)+1));