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 commandline argument.
Store the data in an array of structures.
Calculate the average marks of the students and print it
AlgorithmPseudo Code
Define a Structure:
Create a structure Student to store each student's name, roll number, and
marks.
CommandLine Argument:
In the main function, check if a filename is provided as a commandline
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
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
Bandar
Abdullah
Expected Output:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
