/*
	Demonstration of different ways to manage a group of structs before linked lists are introduced
	This version is an array of structs so that malloc() and free() are not needed
	
	Author:  Barbara Z. Johnson
	Date: November 7, 2019
	Revised: 


*/

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

typedef struct {
	char g_name[31];
	char f_name[31];
	int year;
	char email[22];
} Applicant;


int main() {
	int numapps = 0;
	printf("Number of applicants? \n");
	scanf("%d", &numapps);
	Applicant roster[numapps];
	
	for(int i = 0; i < numapps; i++) {
		printf("Entering information for applicant %d: \n", i);
		printf("Given name: ");
		scanf("%s", roster[i].g_name);
		printf("Family name: ");
		scanf("%s", roster[i].f_name);
		printf("Email address: ");
		scanf("%s", roster[i].email);	
		printf("Year in school (as a number): ");
		scanf("%d", &roster[i].year);	
		char temp = getchar();  // chomp the newline
	
	}
	
	printf("======================================================\n");
	for(int i = 0; i < numapps; i++) {
		printf("Printing the information for applicant %d: \n", i);
		printf("Name: ");
		printf("%s ", roster[i].g_name);
		printf("%s\n", roster[i].f_name);
		printf("Email address: ");
		printf("%s\n", roster[i].email);	
		printf("Year in school (as a number): ");
		printf("%d\n", roster[i].year);	

	
	}
    
    printf("======================================================\n");
    printf("In reverse order just to show how it's done ....\n");
    for(int i = numapps - 1; i >= 0; i--) {
        printf("Printing the information for applicant %d: \n", i);
        printf("Name: ");
        printf("%s ", roster[i].g_name);
        printf("%s\n", roster[i].f_name);
        printf("Email address: ");
        printf("%s\n", roster[i].email);
        printf("Year in school (as a number): ");
        printf("%d\n", roster[i].year);

    
    }
	
	

	return 0;
}
