Question #261000

Write a program that will input student’s information (i.e. name, id, cgpa) who have enrolled

for CSE-207 course in Summer 2020. You have to declare a pointer variable to input the

information and dynamically allocate memory for storing information of each student. After

taking input find out the student name who has obtained the highest GPA.


Expert's answer

#include <stdio.h>
#include <stdlib.h>
struct student{
 char ID[20];
 char name[20];
 float CGPA;
} m[1000];
int main() {
 int n;
 FILE *ptr;
 
 if ((ptr = fopen("student.details","wb")) == NULL){
 printf("Error! cannot open file");
 exit(1);
 }
 int x = 0;
 printf("Input students information:\n");
 while (1) {
 printf("For the student %d: \n", x + 1);
 printf("Input ID: ");
 scanf("%s", m[x].ID);
 printf("Input name: ");
 scanf("%s", m[x].name);
 printf("Input CGPA: ");
 scanf("%f", &m[x].CGPA);
 if (m[x].CGPA == 0) {
 break;
 }
 x++;
 printf("\n");
 fwrite(&m[x], sizeof(struct student), 1, ptr);
 }
 fclose(ptr);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS