Reputation: 1085
How to assign value to char** in C.
char** departmentList;
departmentList[0] = "hahaha";
above code is running in a function but failed all other places. Im using gcc 10.2.0 as the compiler.
Upvotes: 0
Views: 472
Reputation: 75062
You must allocate some buffer to departmentList
before dereferencing that.
char** departmentList;
departmentList = malloc(sizeof(*departmentList)); // allocate
departmentList[0] = "hahaha";
Add #include <stdlib.h>
(if it is not present) to use malloc()
.
Upvotes: 1