I have a question about linked lists. For example, I have the following structures and functions.
struct node {
int value;
struct node *next;
};
struct entrynode {
struct node *first;
struct node *last;
int length;
};
void addnode(struct entrynode *entry) {
struct node *nextnode = (struct node *)malloc(sizeof(struct node));
int temp;
if(entry->first == NULL) {
printf("Please enter an integer.\n");
scanf("%d", &temp);
nextnode->value = temp;
nextnode->next = NULL;
entry->first = nextnode;
entry->last = nextnode;
entry->length++;
} else {
entry->last->next = nextnode;
printf("Please enter an integer.\n");
scanf("%d", nextnode->value);
nextnode->next = NULL;
entry->last = nextnode;
entry->length++;
}
}
In the first part of the if statement, I store the input in a temp variable and then assign it to a field in the structure. Otherwise, I tried to assign it directly, which did not work. How can I assign it directly?
Thank you for your time.
source
share