Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Description: For the lab assignment you are given information about students in

ID: 3897479 • Letter: D

Question

Description: For the lab assignment you are given information about students in a class (name, ID and GPA) and you need to compute a few statistics (max, min and average GPA) about the students and perform some linear search operation. All the students' information is stored in an input file. Below is the input file for the lab assignment. It has the number of students (first line), student's name, ID (5 digits) and GPA (a float). John 12345 3.5 Beth 12345 3.2 Murphy 57465 4.0 Donald 88888 3.8 The first entry in the file is the size of the input. Implement the following functions for the lab assignment. int read_info(char*, int , char**, float*): It takes four arguments, input file names (char) and three arrays of type int* , char** and float* to store the student ID, name and GPA respectively First open the input file using the file name provided by the user (from the command line). As mentioned earlier, the first line of the file is the size of the input. Read that number to run a loop. In a loop read information for each student and store them in the three arrays passed to function (int, char and float array). Close the input file after the use. At the end the function returns the size of the input. This function

Explanation / Answer

Note : I will complete the program.Thank You

______________

#include <stdio.h>

#include <math.h>

#include <stdlib.h>

#include <string.h>

int read_info(char*,int*,char**,float*);

void print_array(int*,char**,float*,int);

int main ()

{

//Declaring variables

FILE *f1;

char filename[30]="studentsInfo.txt";

int size;

//Opening the output file in read mode

f1 = fopen(filename,"r");

  

if(f1 == NULL)

{

printf("** File not found **");

exit(1);

}   

else

{

fscanf(f1,"%d",&size);

//closing the files

fclose(f1);

char **names;

names = malloc(sizeof(char*) * size);

  

float gpa[size];

int id[size];

int n=read_info(filename,id,names,gpa);

  

print_array(id,names,gpa,n);

  

  

}

return 0;

}

int read_info(char* filename,int* id,char** names,float* gpa)

{

int count=0;

int ch=0;

char buff[BUFSIZ];

FILE *f1;

f1 = fopen(filename,"r");

while ((ch = fgetc(f1)) != EOF)

{

if (ch == ' ')

{

fscanf(f1,"%d%f",&id[count],&gpa[count]);

//printf("%s ",names[count]);

count++;

}

}

//closing the files

fclose(f1);

  

return count;

}

void print_array(int* id,char** names,float* gpa,int n)

{

int i;

for(i=0;i<n;i++)

{

printf("jhi");

}

  

}

______________