The code, so you don't have to download it just to see.
Code:
#include <stdio.h>
#include <stdlib.h>
struct student
{
char name[15];
char surname[15];
};
struct node
{
struct student data;
struct node* next;
};
struct node* head=NULL;
struct node* curr;
void output();
void input();
void append();
void save();
int main(void)
{
int option;
FILE *fl;
struct student* temp = (struct student*)malloc(sizeof(struct student));
fl = fopen("agenda.dat","rb");
if (fl != NULL)
while(fread(temp,sizeof(struct student),1,fl)!=(size_t)NULL)
{
append(temp);
}
do
{
//system("cls"); //Windows Only...
printf("Menu\n1: Add\n2: View\n3: Save\n0: Exit\n\nOption: ");
scanf("%d",&option);
if(option==1)
input();
else if(option==2)
output();
else if(option==3)
save();
}
while(option);
if (head != NULL)
save();
return(0);
}
void append(struct student* new)
{
curr = (struct node*)malloc(sizeof(struct node));
(*curr).data = *new;
(*curr).next = head;
head = curr;
}
void input(void)
{
struct student* temp = (struct student*)malloc(sizeof(struct student));
printf("Name: ");
scanf("%s",(*temp).name);
printf("Surname: ");
scanf("%s",(*temp).surname);
append(temp);
free(temp);
}
void output()
{
curr = head;
if (head!=NULL)
while(curr)
{
printf("\nName: %s\n",(*curr).data.name);
printf("Surname: %s\n",(*curr).data.surname);
curr=(*curr).next;
}
else
printf("Noobs\n");
}
void save()
{
FILE *fl;
fl = fopen("agenda.dat","wb");
curr = head;
while(curr)
{
fwrite(&(*curr).data, sizeof((*curr).data), 1 , fl );
curr=(*curr).next;
}
fclose(fl);
}