Assigning a value to an integer in a C linked list
- by Drunk On Java
Hello all. I have a question regarding linked lists. I have the following structs and function for example.
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 input into a temp variable and then assign that to a field in the struct. The else branch, I tried to assign it directly which did not work. How would I go about assigning it directly?
Thanks for your time.