Attempt to create linked list, but error with pointer assignment

I am trying to create a linked list and create some methods. However, I am getting the error:

The assignment makes a pointer from an integer without translation.

Here is my code:

#include <stdio.h>
#include <stdlib.h>
#include "students.h"


node_ptr create(void)
{
    node_ptr students = (node_ptr) malloc(sizeof(struct node));
    students->ID = 0; 
    students->name = NULL;
    students->next = NULL; 
    return students;
}

void insert_in_order(int n, node_ptr list)
{
    node_ptr before = list;
    node_ptr new_node = (node_ptr) malloc(sizeof(struct node));
    new_node->ID = n; //error is here I think


    while(before->next && (before->next->ID < n))
    {
        before = before->next;
    }

    new_node->next = before->next;
    before->next = new_node;
}

      

+2


a source to share


1 answer


If the error is on the commented line, then perhaps ID is a pointer and not an int. This will work fine:

students->ID = 0; 

      



because it sets the pointer to NULL, so it compiles with no errors / warnings.

0


a source







All Articles