I have a chunk of memory I'm declaring on the heap.
char *str;
str = (char *)malloc(sizeof(char) * 10);
I have a const string.
const char *name = "chase";
Because *name is shorter than 10 I need to fill str with chase plus 5 spaces.
I've tried to loop and set str[i] = name[i] but there's something I'm not matching up because I cannot assign spaces to the additional chars. This was where I was going, just trying to fill str with all spaces to get started
int i;
for (i = 0; i < 10; i++)
{
strcpy(str[i], ' ');
printf("char: %c\n", str[i]);
}
strcpy()is for you.'\0'byte. Or if you want 10 actual chars, then make the array length 11, so you have room for the'\0'.