c language. Mostly need help with 4 and 5 Declare a student structure that conta
ID: 3774261 • Letter: C
Question
c language. Mostly need help with 4 and 5
Declare a student structure that contains: Student's first and last name Student ID Create the following functions: getStudentlnfo(void) Declares a single student, uses printf()/scanf() to get input Returns the single student back printStudentInfo(student_t *st_ptr) Takes the pointer to a student (to avoid making a copy) Prints out all of the student information Declare an array of five students Using a for loop and getStudentlnfo() function, get input of all the students Using a for loop and printStudentlnfo() function, print all the output of all studentsExplanation / Answer
#include <stdio.h>
#include <string.h>
struct student
{
int id;
char first_name[30];
char second_name[30];
// float percentage;
};
//function for getting student info
struct student getStudentInfo(){
struct student stu;
printf("Enter first name of the student : ");
scanf("%s",stu.first_name);
printf("Enter second name of the student : ");
scanf("%s",stu.second_name);
printf("Enter id of the student : ");
scanf("%d",stu.id);
return stu;
}
//function printinfo
void printStudentInfo(struct student *st_ptr ){
printf("First Name : %s",st_ptr->first_name," ");
printf("Second Name : %s",st_ptr->second_name," ");
printf("Student ID : %d",st_ptr->id," ");
}
int main()
{
int i;
struct student record[5]; //array to store student information
/ for(i=0;i<5;i++)
record[i]=getStudentInfo();
for(i=0;i<5;i++)
printStudentInfo(&record[i]);
//
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.