I have the next code:
1 2 3 4
|
new_->first = NULL;
new_->last = NULL;
new_->sum = 0;
new_->len = 0;
|
is there a faster way you can change the structure variables or does it have to be one by one?
p.s this is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node* next;
struct node* prev;
};
struct mainlist
{
struct node* first;
struct node* last;
int sum;
int len;
};
typedef struct mainlist* list;
list createList(void)
{
list new_ = (list)malloc(sizeof(struct mainlist));
//set structure values to 0.
new_->first = NULL;
new_->last = NULL;
new_->sum = 0;
new_->len = 0;
return new_;
}
int main()
{
list mylist = createList();
return 0;
}
|
Last edited on
Is this C, or C++? Assuming C:
This really isn't a problem you should worry about. It's a hell of a lot cleaner to have four clear commands. But you can use memset.
memset(mylist, 0, sizeof(*mylist));
Last edited on
thank you :) it works now