#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.cvs", "a");
	
	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.cvs","r");

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

	struct Student *students2 = read_file_to_array(file, n, students2);

	fclose(file);

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

	free(students2);
	return 0;
}
