Answer to Question #261000 in C for Sadiya

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.


1
Expert's answer
2021-11-04T08:37:55-0400
#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!

Comments

Sadiya Afrin
04.11.21, 16:16

Thanks for answering my assignment...

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS