Question: Write a C program that reads student information ( name , roll number, marks ) from a file and calculates the average marks of the

Write a C program that reads student information (name, roll number, marks) from a file and
calculates the average marks of the students. The program should:
Use a structure to store student information.
Read the data from a file whose name is provided as a command-line argument.
Store the data in an array of structures.
Calculate the average marks of the students and print it.
Algorithm/Pseudo Code
Define a Structure:
Create a structure Student to store each student's name, roll number, and
marks.
Command-Line Argument:
In the main function, check if a filename is provided as a command-line
argument.
If not, print an error message and exit.
Reading File Data:
Use fopen to open the file.
Read the student details using fscanf and store them in an array
of Student structures.
Close the file after reading.
Calculate Average Marks:
Initialize a variable totalMarks to 0.
Loop through the array of students, adding each student's marks
to totalMarks.
Calculate the average by dividing totalMarks by the number of students.
Print Results:
Print the average marks.
Sample Input and Output
Assume a file named students. txt:
Ali 10190.5
Bandar 10285.0
Abdullah 10378.5
Expected Output:
Write a C program that reads student information

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!