#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "students.h"


int
main()
{
	int n;
	printf("Enter the amount of students:");
	scanf("%d", &n);
	getchar();

	struct Student *students = allocate_array(n);
	
	fill_array(n, students);
	
	FILE *file = NULL;
	file = fopen("students.bin", "wb");
	
	bin_write_array(file, n, students);
		
	fclose(file);
	free(students);


	puts("Students to read:");
	scanf("%d",&n);
	getchar();

	if(n <= 0)
		exit(0);


	file = fopen("students.bin","rb");

	if(!file){
		puts("Could not open file!");
		exit(0);
	}

	struct Student *students2 = allocate_array(n);
	
	bin_read_file_to_array(file, n, students2);

	fclose(file);

	puts("From file:");
	print_array(students2, n);

	free(students2);
	return 0;
}
