#include <stdlib.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 = bin_read_file_to_array(file, n);

	fclose(file);

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

	free(students2);
	return 0;
}

