Skip to main content

Array of struct C langagelanguage

In my program, I have to create structs, in my case, I have struct Processor here is my example:

struct Processor{
    int id;
    struct Task **task;
}

inIn the main I create set of processors (2 processors for example), and I have to add in tasks in each processor using this function struct Processor * create_processor(int id, struct Task **task );

hereHere is the function:

struct Processor * create_processor(int id, struct Task **task){
    struct Processor * pr = (struct Processor *) (malloc(sizeof(struct Processor)));
    pr->id = id;
    //how to initialize Task set??
    return pr;
}

Now how to initialize the set of tasks in the function? and how to use elements of taskset? I used processor[1]->task[1]->id = 5; but it returns ERROR Segmentation fault (core dumped)

Help please

Array of struct C langage

In my program, I have to create structs, in my case, I have struct Processor here is my example:

struct Processor{
    int id;
    struct Task **task;
}

in the main I create set of processors (2 processors for example), and I have to add in tasks in each processor using this function struct Processor * create_processor(int id, struct Task **task );

here is the function:

struct Processor * create_processor(int id, struct Task **task){
    struct Processor * pr = (struct Processor *) (malloc(sizeof(struct Processor)));
    pr->id = id;
    //how to initialize Task set??
    return pr;
}

Now how to initialize the set of tasks in the function? and how to use elements of taskset? I used processor[1]->task[1]->id = 5; but it returns ERROR Segmentation fault (core dumped)

Help please

Array of struct C language

In my program, I have to create structs, in my case, I have struct Processor here is my example:

struct Processor{
    int id;
    struct Task **task;
}

In the main I create set of processors (2 processors for example), and I have to add in tasks in each processor using this function struct Processor * create_processor(int id, struct Task **task );

Here is the function:

struct Processor * create_processor(int id, struct Task **task){
    struct Processor * pr = (struct Processor *) (malloc(sizeof(struct Processor)));
    pr->id = id;
    //how to initialize Task set??
    return pr;
}

Now how to initialize the set of tasks in the function? and how to use elements of taskset? I used processor[1]->task[1]->id = 5; but it returns ERROR Segmentation fault (core dumped)

Help please

Fixed formatting, grammar
Source Link
dbush
  • 232.9k
  • 27
  • 261
  • 334

In my program, iI have to create structs, in my case, i I have struct Processor here is my exempleexample:

Structstruct Processor{int id;
            int id;
    struct Task **task;       
}

in the main iI create set of processors (2 processors for exempleexample), and iI have to add in tasks in each processor using this function struct Processor * create_processor(int id, struct Task **task );

here is the function:

struct Processor * create_processor(int id, struct Task **task){
    struct Processor * pr = (struct Processor *) (malloc(sizeof(struct Processor)));
    pr->id = id;
    //how to initlyseinitialize Task set??
    return pr;
}

nowNow how to initilyseinitialize the set of tasks in the function? and how to use elements of taskset  ? i I used processor[1]->task[1]->id = 5; but it returnreturns ERROR Segmentation fault (core dumped)

Help please

In my program, i have to create structs, in my case, i have struct Processor here is my exemple:

Struct Processor{int id;
                 struct Task **task;      }

in the main i create set of processors (2 processors for exemple), and i have to add in tasks in each processor using this function struct Processor * create_processor(int id, struct Task **task );

here is the function:

struct Processor * create_processor(int id, struct Task **task){
struct Processor * pr = (struct Processor *) (malloc(sizeof(struct Processor)));
pr->id = id;
//how to initlyse Task set??
return pr;
}

now how to initilyse the set of tasks in the function? and how to use elements of taskset  ? i used processor[1]->task[1]->id = 5; but it return ERROR Segmentation fault (core dumped)

Help please

In my program, I have to create structs, in my case, I have struct Processor here is my example:

struct Processor{
    int id;
    struct Task **task; 
}

in the main I create set of processors (2 processors for example), and I have to add in tasks in each processor using this function struct Processor * create_processor(int id, struct Task **task );

here is the function:

struct Processor * create_processor(int id, struct Task **task){
    struct Processor * pr = (struct Processor *) (malloc(sizeof(struct Processor)));
    pr->id = id;
    //how to initialize Task set??
    return pr;
}

Now how to initialize the set of tasks in the function? and how to use elements of taskset? I used processor[1]->task[1]->id = 5; but it returns ERROR Segmentation fault (core dumped)

Help please

Source Link
ikram
  • 25
  • 6

Array of struct C langage

In my program, i have to create structs, in my case, i have struct Processor here is my exemple:

Struct Processor{int id;
                 struct Task **task;      }

in the main i create set of processors (2 processors for exemple), and i have to add in tasks in each processor using this function struct Processor * create_processor(int id, struct Task **task );

here is the function:

struct Processor * create_processor(int id, struct Task **task){
struct Processor * pr = (struct Processor *) (malloc(sizeof(struct Processor)));
pr->id = id;
//how to initlyse Task set??
return pr;
}

now how to initilyse the set of tasks in the function? and how to use elements of taskset ? i used processor[1]->task[1]->id = 5; but it return ERROR Segmentation fault (core dumped)

Help please