Hello,
I am tring to add new structure to slist.
I am not sure this is the right way to do it.
I have a broblem when i'm tring to put the fildes id and name (run time eror).
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct student {
char *name;
int id;
struct clist *courses;
} student;
typedef struct course {
char *title;
int number;
struct slist *students;
} course;
typedef struct slist {
student *info;
struct slist *next;
} slist;
typedef struct clist {
course *info;
struct clist *next;
} clist;
//prototypes
slist* add_student(slist *students, char *name, int id);
//main function - only to check the program
void main(){
char *name[256];
int id;
slist *students = NULL;
printf("Enter your name\n");
scanf("%s",&name);
printf("Enter your id\n");
scanf("%d",&id);
add_student(students,name,id);
}
//Basic Operations
slist* add_student(slist *students, char *name, int id){
slist *head = (slist*) malloc(sizeof(slist));
strcpy(head->info->name, students->info->name);
head->info->id = id;
if (!head ) return NULL;
head->next = students;
return head;
}