Hello guys,
Can someone explain what is going on on this code?
1. why we needed **p in the function AllocString?
2. why if I change AllocString(strlen(s), ©); to AllocString(strlen(s)-7, ©); I can still get a good result?
Thanks!
#include <stdlib.h>
int main() {
char *s="example";
char *copy=NULL;
AllocString(strlen(s), ©);
strcpy(copy, s);
printf("%s\n", copy);
free(copy);
}
int AllocString(int len, char **p) {
char *str=malloc(len+1);
if(str==NULL)
return 0;
*p=str;
return 1;
}