I am just practicing to understand dynamic allocation in C. I am getting a segmentation fault error. I am not sure where I made mistake.
int wordcount = 5;
char **args = (char**)malloc(wordcount * sizeof(char*));
for ( int i = 0; i < wordcount; i++) {
args[i] = (char*)malloc(167 * sizeof(char));
}
int c=0;
while(c < wordcount){
strcpy("hello\n", args[c]);
c++;
}
strcpy()did you read?strcpyreference. By the way, just about any tutorial or book would have told you how to usestrcpyalready.strcpy("hello\n", args[c]);==>strcpy(args[c], "hello\n");char ** args;definesargsto be a pointer to pointer tochar. Also there is no data type "string" in C.