this:
char** address;
address = (char**)malloc(2048);
address[0] = "/mnt/D/WorkSpace/C/NeoDM";
show_status_of_git_repo(address);
As you can see, i don't know how to allocate memory for address**. Since it can be any size. What's the best approach for alloacting memory in these situations?
I suppose you could guess what the size would be on average and use that. Then if you run out of space in your array, you can reallocate memory to make it bigger.
array of string : char **arrString = (char ** ) malloc (sizeof(char *) * array_size); for(li = 0;li < array_size;li++) arrString[li] = (char *)malloc(sizeof(char) * max_string_length); strcpy(arrString[idx],"something");
Обсуждают сегодня