Question
Please modify my C program so it prints out the desired output correctly.( Do not just copy and paste my code as the answer, I
Please modify my C program so it prints out the desired output correctly.( Do not just copy and paste my code as the answer, I will downvote. The code needs to successfully output the desired output by which the files contents are layed out )
The output from inputing the large student file should be organized and one right after the other. My code is outputting a messy output, please fix this.
Here are the program directions:
Here is the output of my program(See the breaks, which shouldn't happen). Also the spacing isn't right, something is wrong:
Here is my program that needs to be modified:
#include
#include
#include
// Prototype declaration of functions
void getGrades(int ROWS, int COLS, int grades[ROWS][COLS], char students[COLS][20]);
void printGrades(int ROWS, int COLS, int grades[ROWS][COLS]);
void getStudents(int COLS, char students[COLS][20]);
void printStudents(int COLS, char students[COLS][20]);
void calcGrades(int ROWS, int COLS, int grades[ROWS][COLS], char Fgrades[]);
void printFinalGrades(int COLS, char Fgrades[]);
// File pointer
FILE *fptr;
// main function definition
int main(int argc,char **argv)
{ // To store number of students and number of assignments if(argc 2){ printf(" Too Much Argument Please give only file name "); return -1; } int stu = 0, assign = 0; // Opens the file in read mode // command line argument argv[1] contains the file name fptr = fopen(argv[1], "r"); // Checks if the file pointer is NULL then display the error message and stop if (fptr == NULL) { printf("Cannot open file %s ",argv[1]); exit(0); }// End of if condition // Reads number of students and number of assignments from file fscanf(fptr, "%d%d", &stu, &assign); printf(" Number of Students = %d Number of Assignment = %d", stu, assign); // Matrix for student names char students[stu][20]; // Matrix for assignment marks int grades[assign][stu]; // Array for grade char final_grade[stu]; // Calls the functions to read data from file and calculate grade getStudents(stu, students); getGrades(assign, stu, grades, students); calcGrades(assign, stu, grades, final_grade); printf(" "); // Calls the function to display data printStudents(stu, students); printGrades(assign, stu, grades); printFinalGrades(stu, final_grade); return 0; }// End of main function
// Function to display final grade of all the students
void printFinalGrades(int COLS, char Fgrades[])
{ int i = 0; // Loops till number of students for (i = 0; i
// Function to calculate grade
void calcGrades(int ROWS, int COLS, int grades[ROWS][COLS], char Fgrades[])
{ // Initializes the variables int avg = 0; int sum = 0; int i = 0, j = 0; // Loops till number of cols for (i = 0; i = 90) // Assign grade as 'A' Fgrades[i] = 'A'; // Otherwise checks if average is greater than or equals to 80 else if (avg >= 80) // Assign grade as 'B' Fgrades[i] = 'B'; // Otherwise checks if average is greater than or equals to 70 else if (avg >= 70) // Assign grade as 'C' Fgrades[i] = 'C'; // Otherwise checks if average is greater than or equals to 60 else if (avg >= 60) // Assign grade as 'D' Fgrades[i] = 'D'; // Otherwise less than 60 else // Assign grade as 'F' Fgrades[i] = 'F'; }// End of for loop }// End of function
// Function to display student names
void printStudents(int COLS, char students[COLS][20])
{ int i = 0; int numA = COLS; // Loops till number of columns for (i = 0; i
// Function to read student names from file
void getStudents(int COLS, char students[COLS][20])
{ int i = 0,len = 0; // Loops till number of columns for (i = 0; i
// Function to display grade of each student
void printGrades(int ROWS, int COLS, int grades[ROWS][COLS])
{ int i = 0, j = 0; // Loops till number of rows for (i = 0; i
// Function to read grade from the file
void getGrades(int ROWS, int COLS, int grades[ROWS][COLS], char students[COLS][20])
{ int i = 0, j = 0; // Loops till number of rows for (i = 0; i
You must take the input file name on the command line Be sure to have simple error checking to be sure the file exists and was successfully opened. The input file will have the following format: First line: Number of students Second Line: Number of assignments Third Line: Student Names, space delimited Fourth+ Line(s) Grades for all students for one assignment, space delimited. Example of input file format: 2 3 Joel Sophie 100 97 78 92 62 70 Requirements: - Your program must read input from a file in the proper format, NOT stdin - Your program should accept the filename from the commandline as shown in the example below Your program should be able to handle a file of any reasonable size. (I will not use excessively long student names, but there may be MANY students and grades.) Do not just make your arrays really large, you need to dynamically allocate them. Example: $ ./a.out infile.txt Joel 100 78 62 Sophie 97 92 70 You must take the input file name on the command line Be sure to have simple error checking to be sure the file exists and was successfully opened. The input file will have the following format: First line: Number of students Second Line: Number of assignments Third Line: Student Names, space delimited Fourth+ Line(s) Grades for all students for one assignment, space delimited. Example of input file format: 2 3 Joel Sophie 100 97 78 92 62 70 Requirements: - Your program must read input from a file in the proper format, NOT stdin - Your program should accept the filename from the commandline as shown in the example below Your program should be able to handle a file of any reasonable size. (I will not use excessively long student names, but there may be MANY students and grades.) Do not just make your arrays really large, you need to dynamically allocate them. Example: $ ./a.out infile.txt Joel 100 78 62 Sophie 97 92 70
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started