Getting a segmentation fault for the following code. Please advise.
struct columns {
char* c_name;
char* c_type;
char* c_size;
};
int main(int argc, char* argv[])
{
int column_num = 3;
struct columns col[10];
//columns *col = (columns*) malloc (sizeof(columns) * column_num);
strcpy(col[0].c_name, "PSID");
strcpy(col[0].c_type, "INT");
strcpy(col[0].c_size, "4");
}
I am using 2 ways to allocate space for columns structure but continue to get a segmentation fault. Am I missing something?
Try this (
strduptakes care of storage but remember to free when you are done):