Strcpy and malloc issues
- by mrblippy
Hi, i am having trouble getting a method relating to a linked list working, i get the errors:
assignment makes pointer from integer without a cast and passing argument 1 of âstrcpyâ makes pointer from integer without a cast. i have tried to include all the relevant code, but let me know if you need more info. thanks.
struct unit
{
char code[5];
char *name;
node_ptr students;
};
typedef struct node *node_ptr;
struct node
{
int student_id;
char *studentname;
node_ptr next;
};
void enrol_student(struct unit u[], int n)
{
int i, p;
int student_id = 0;
char code_to_enrol[7];
char buffer[100];
node_ptr studentslist;
scanf("%s\n", code_to_enrol);
for(i=0; i <= n; i++)
{
studentslist = u[i].students;
if(strcmp(u[i].code ,code_to_enrol)<=0)
{
scanf("enter student details %d %s\n", &studentID, buffer);
p = (char *) malloc (strlen(buffer)+1);
strcpy(p, buffer);
insert_in_order(student_id, buffer, studentslist);
}
}
}
void insert_in_order(int n, char *i, node_ptr list)
{
node_ptr before = list;
node_ptr students = (node_ptr) malloc(sizeof(struct node));
students->ID = n;
students->name = *i;
while(before->next && (before->next->ID < n))
{
before = before->next;
}
students->next = before->next;
before->next = students;
}