Ok firstly I'll explain my assignment. For this assignment I have to use dynamic memory allocation which I am having no problems with. What I am having a problem with is figuring out the correct way to work my assignment. For my assignment I need to create a program that prompt the user to enter how many students they have then ask for the following information; Student ID, Birthdate, and Phone number. I need to use a loop to prompt the user to enter all the students information. I need to create a loop that will scan through all the student IDs and find the oldest student using their birthdate (The loop must be able scan through more then 3 students).
Here is my code, I've gotten some suggestions and even bits of code from you guys. Here is my code what is the best way to go about creating a loop that will search through all the students and find the oldest?
Thank you.
#include <stdio.h>
#include <stdlib.h>
struct studentDataType
{
int studentID;
int year;
int month;
int day;
long long phone;
};
int main (void)
{
struct studentDataType *studentRecords=NULL;
unsigned int students;
unsigned int studentID;
unsigned int year;
unsigned int month;
unsigned int day;
unsigned long phone;
printf("How many students are you entering records for:\n");
scanf("%d", &students);
studentRecords = malloc(sizeof(struct studentDataType) * students);
int i=0;
for (i; i != students ; ++i) {
printf("Enter information for student as follows (ID, DOB year, DOB month, DOB day, Phone): %d\n", i+1);
struct studentDataType * s = &studentRecords[i];
scanf("%u %u %u %u %u", &(s->studentID), &(s->year), &(s->month), &(s->day), &(s->phone));
}
}