char name[] = "lady gaga";
char *ptr;
ptr = (char*) malloc(sizeof(name) * sizeof(char))
And then it's okey to initialize it through assignment or strcpy
ptr = name;
or
strcpy(ptr, name);
Calloc is same as malloc:
ptr = (char*) calloc(sizeof(name), sizeof(char))
When you need copy an array of char to an array of char, the one way is use strcpy function
char name[] = "Indonesia";
char data[100];
strcpy(data, name);
No comments:
Post a Comment