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

Input txt Follow the instruction below to develop the program. 1) Download the d

ID: 3820479 • Letter: I

Question


Input txt Follow the instruction below to develop the program. 1) Download the data file input.txt from Pilot and add it to your project. This text file contains a list of student records, showing their marks and respective grades. Each student record is on a separate line. The first line in the file contains the number of records in the file. 2) in your C program, declare structure student as follows: typedef struct student char name (50) int marks; char grade [10]; struct student next; student; 3) Write the following functions: student readStudentData(student head); This function reads the number of records to be read (i.e., the first line of the input file). It should then use a for loop to read student data. If the FILE is empty, an appropriate error message should be printed out. void printstudentData(student head); This function prints the data of studentsto the output. If there is no data, an appropriate message should be displayed. 4) Main function In the main function declare student head a NULL Issue call head readStudentData(head); to read student data from the text file into a linked list or queue, and then call printStudentData (head) to display student data in the order they appear in the file.

Explanation / Answer

#include <stdio.h>
#include <string.h>
#include <malloc.h>

typedef struct student{
char name[50];
int marks;
char grade[10];
struct student *next;
}student;

student *stud, *ptr;
student *tail = NULL;

student *insert_student_last(student *head,char name[], int marks, char grade[])
{
  
return head;
}


student *readStudentData(student *head){
FILE *fptr;
char buff[255];
char name[255];
char marks[255];
char grade[255];
fptr = fopen("input.txt", "r");
if (fptr == NULL)
{
printf("Cannot open file ");
exit(0);
}
int num_of_students = atoi(fgets(buff, 255, (FILE*)fptr));
printf("Number of students in the Class : %d ", num_of_students);
printf("%s ","Details of the Students" );
int i=0;
for(i=0;i<num_of_students;i++){
fscanf(fptr, "%s", name);
fscanf(fptr, "%s", marks);
fscanf(fptr, "%s", grade);

// insert at last
stud = (student *)malloc(sizeof(student));
memcpy(stud->name, name, 50);
stud->name[49] = 0;
stud->marks = atoi(marks);
memcpy(stud->grade, grade, 10);
stud->grade[9] = 0;
stud->next = NULL;

if (head == tail && tail == NULL)
{
head = tail = stud;
head->next = NULL;
tail->next = NULL;
}
else
{
tail->next = stud;
tail = stud;
tail->next = NULL;
}

}
return head;
}

void printStudentData(student *head){
if (head == NULL)
{
printf("No students in the list to display ");
}
else
{
for (ptr = head;ptr != NULL;ptr = ptr->next)
{
printf("Name : %s Marks : %d Grade : %s ", ptr->name,ptr->marks,ptr->grade);
}
}
}

int main()
{
student *head= NULL;
head = readStudentData(head);
printStudentData(head);
}