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, but after implementing them I'm even more confused on what I should do. Please take a look at it and critique me.
EDIT: I also added in on the code where I'm receiving and error
Thank you.
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int * studentData= NULL;
int * studentDataType=NULL;
int students;
int studentID;
int year;
int month;
int day;
long long phone;
printf("How many students are you entering records for:
");
scanf("%d", &students);
studentData=(int*)malloc((sizeof(int)*students));
struct studentDataType
{
int studentID;
int year;
int month;
int day;
long long phone;
};
//invalid operands to binary * (have 'int' and 'int *')
studentDataType *studentData = (studentDataType*)malloc(numberOfStudents *sizeof(studentData));
for (int i = 0 ; i < students ; ++i)
{
printf("%d, %d, %d, %d, %d
", studentID, year, month, day, phone);
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…