J
JS
I have this struct:
struct list {
char *thread;
struct list *previous;
struct list *next;
};
struct list *n;
I then have this function:
void addthread(char *t){
n = (struct list *)malloc(sizeof(struct list));
printf("%s\n",t);
strcpy(n->thread,t);
}
In my main function I give the addthread function this argument:
addthread("test");
when I run the program it prints "test" from line 2 in the addthread
function but then I gives the error:
Segmentation fault
I guess it has something to do with this statment:
strcpy(n->thread,t);
But why is that statement illegal?
struct list {
char *thread;
struct list *previous;
struct list *next;
};
struct list *n;
I then have this function:
void addthread(char *t){
n = (struct list *)malloc(sizeof(struct list));
printf("%s\n",t);
strcpy(n->thread,t);
}
In my main function I give the addthread function this argument:
addthread("test");
when I run the program it prints "test" from line 2 in the addthread
function but then I gives the error:
Segmentation fault
I guess it has something to do with this statment:
strcpy(n->thread,t);
But why is that statement illegal?