0

Why am I getting "segmentation fault(core dumped)" error after adding code for task t2 ? I don't get the error if I removed those lines. I am creating a Task to assign it to a pointer variable in a node structure. The insert and traverse functions work and the values of variables of t1 get printed. But only if I remove the five lines of code for Task t2.

#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>

typedef struct {
    char *name;
    int tid;
    int priority;
    int burst;
} Task;

void insert(struct node **a, Task *b);
void traverse(struct node *a);


int main(int argc, char *argv[])
{
    Task *t1;
    t1->name = "t1";
    t1->tid = 2000;
    t1->priority = 1;
    t1->burst = 20;

    struct node *first = NULL;  
    insert(&first,t1);
    traverse(first);

    Task *t2;
    t2->name = "t1";
    t2->tid = 2000;
    t2->priority = 1;
    t2->burst = 20;


    return 0;
}
Out Of Bounds
  • 165
  • 2
  • 9

1 Answers1

0

Please allocate some memory for t1 and t2 struct pointers or point them to valid address of other same struct object. you cant just use it like that.