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

Help me Modify the C program below to create a more robust program to separate a

ID: 3574653 • Letter: H

Question

Help me Modify the C program below to create a more robust program to separate a large assignment feedback. Use comments also
text file into individualized feedback files, one per person.
Functional Requirements
• All functional requirements from current written program must be satisfied with the following
changes:
o All output files must be put in a subdirectory under the current directory. The
name of that subdirectory is "Individual".
If the subdirectory exists, use it. If it does not exist, create it, displaying
an error message and quitting the program if your attempt to create it fails.
o The input filename must be obtained from the command line as the first argument
on the command line.
If there are not the appropriate number of arguments on the command line,
display an error message and quit the program.
Other Requirements
• Error checking is required for all file I/O function calls and all relevant string functions if
they can fail. If there is an error or missing information, display an appropriate error
message and quit the program.
o The input file might deviate from the specifications. Thus, you need the error
checking to avoid crashing the program.
o One specification that you can still depend on is that individual input lines will
not exceed 400 characters.
• In your storage struct, separate the Mark Information into two fields: an int representing
the mark and a string representing the mark description. You must extract these two
fields from the one input line.
o In your output for each student, put the Mark Description after the "Comments: "
heading (and the Mark line should not have the second colon).
• An example of the output of a student entry is:
Flintstone, Fred
Feedback on Assignment 2
Mark: 80
Comments: Meets or almost meets expectations.
* Your program exits on any value above 3.
* Your file header comment was missing your name.
* Prototypes incomplete.
NOT
Flintstone, Fred
Feedback on Assignment 2
Mark: 80 Comments: Meets or almost meets expectations.
* Your program exits on any value above 3.
* Your file header comment was missing your name.
* Prototypes incomplete
• If a particular student entry does not have the required content in the correct order,
display an appropriate error message indicating which student it applies to (if
identifiable), skip the rest of this particular student's information, do not create their
output file, and proceed with the next student's entry after the next "END" line.
• It must not use global variables, goto, or exit(). It must not take in user input.
• In the struct, instead of storing each string in an array of 401 chars each, make each such
field a pointer to char that you dynamically allocate to store the string far more efficiently
(i.e. using exactly as much memory as is needed for the string (plus, of course, the nulltermination)).
In doing so, you can use one 401-character-long variable for getting the
user input but then transfer the contents to the block you allocate.
o After you write the data to the output file, free all of your allocated memory.
o If there are less than the maximum number of comments, the unused ones should
have NULL pointers stored in their fields and, ultimately, not written to the output
file.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define max_line_size 400

struct student
{
char* name;
char* assignment_Name;
int* mark;
char* description;
char* comments[10];
};//Declaring Structure to hold the mentioned Data
int main()
{
FILE *feedback_file = fopen("feedback.txt", "r");
//Opening the feedback file in readmode
if (!feedback_file)
//Checking the error of condition while opening the feedback file
{
printf("Error opening feedback.txt file.... ");
return 1;
//Exit from the program if error is there
}

struct student temp;
temp.name = malloc(sizeof(500));
temp.assignment_Name = malloc(sizeof(500));
temp.description = malloc(sizeof(500));
temp.mark = 0;
char fullmarks[401];
//Defining the variable t0 hold the data of each person
while (fgets(temp.name, max_line_size + 1, feedback_file))
//Iterating the file till end
{
int name_length = strlen(temp.name);
if (temp.name[name_length - 1] == ' ')
//Eliminating the newline character from student name
{
temp.name[name_length - 1] = '';

}
fgets(temp.assignment_Name, max_line_size + 1, feedback_file);
//Fetching the Feedback line
fgets(fullmarks, max_line_size + 1, feedback_file);
sscanf(fullmarks, "%d", &temp.mark);

//temp.description = fullmarks[10] ;
//Fetching the mark line
fseek(feedback_file, 10, SEEK_CUR);
//Skipping the "Comments: "
int i;
for (i = 0; i<10; i++)
//Fetching the comments line by line
{
fgets(temp.comments[i], max_line_size + 1, feedback_file);
if (!strcmp(temp.comments[i], "END "))
//Skipping "END " string
{
i--;
break;
}
}

name_length = strlen(temp.name);
char *file_name =(char*) malloc(name_length + 4);
strcpy(file_name, temp.name);
strcpy(file_name + name_length, ".txt");
//Creating the "individualfile.txt" string
FILE *individual_file = fopen(file_name, "w");
//Creating the file and opening in writemode
if (!individual_file)
//Error checking
{
printf("Error Creating %s file", file_name);
return 1;
//Exit from the program if error occurs
}

fputs(temp.name, individual_file);
//Putting the student name into individual file
fputc(' ', individual_file);
//adding new line character since we removed newline character initially
fputs(temp.assignment_Name, individual_file);
//Putting feedback string
fputs(temp.mark, individual_file);
//putting mark string
fputs("Comments: ", individual_file);
//putting "Comments: "
int j;
for (j = 0; j <= i; j++)
{
if (strlen(temp.comments[j]) > 3)
{
fputs(" ", individual_file);
fputs(temp.comments[j], individual_file);
}

}

}
return 0;
}

Explanation / Answer

I made modified statements bold.. please check

/* Your name */
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define max_line_size 400
struct student
{
char* name;
char* assignment_Name;
int* mark;
char* description;
char* comments[10];
};//Declaring Structure to hold the mentioned Data
int main(int argc, char **argv)
{
   if(argc < 2){
       printf("To proceed file name should provide.... ");
       return 1;
   }
   FILE *feedback_file = fopen(argv[1], "r");

   //Opening the feedback file in readmode
   if (!feedback_file)
   //Checking the error of condition while opening the feedback file
   {
   printf("Error opening feedback.txt file.... ");
   return 1;
   //Exit from the program if error is there
   }
   struct student temp;
   temp.name = malloc(sizeof(500));
   temp.assignment_Name = malloc(sizeof(500));
   temp.description = malloc(sizeof(500));
   temp.mark = 0;
   char* fullmarks[];
   //Defining the variable t0 hold the data of each person
   while (fgets(temp.name, max_line_size + 1, feedback_file))
   //Iterating the file till end
   {
       int name_length = strlen(temp.name);
       if (temp.name[name_length - 1] == ' ')
       //Eliminating the newline character from student name
       {
           temp.name[name_length - 1] = '';

       }
       fgets(temp.assignment_Name, max_line_size + 1, feedback_file);
       //Fetching the Feedback line
       fgets(fullmarks, max_line_size + 1, feedback_file);
       sscanf(fullmarks, "%d", &temp.mark);

       //temp.description = fullmarks[10] ;
       //Fetching the mark line
       fseek(feedback_file, 10, SEEK_CUR);
       //Skipping the "Comments: "
       int i;
       for (i = 0; i<10; i++)
       //Fetching the comments line by line
       {
           fgets(temp.comments[i], max_line_size + 1, feedback_file);
           if (!strcmp(temp.comments[i], "END "))
           //Skipping "END " string
           {
               i--;
               break;
           }
       }
       name_length = strlen(temp.name);
       char *file_name =(char*) malloc(name_length + 4);
       strcpy(file_name, temp.name);
       strcpy(file_name + name_length, ".txt");
       //Creating the "individualfile.txt" string
       FILE *individual_file = fopen(file_name, "w");
       //Creating the file and opening in writemode
       if (!individual_file)
       //Error checking
       {
           printf("Error Creating %s file", file_name);
           return 1;
           //Exit from the program if error occurs
       }
       fputs(temp.name, individual_file);
       //Putting the student name into individual file
       fputc(' ', individual_file);
       //adding new line character since we removed newline character initially
       fputs(temp.assignment_Name, individual_file);
       //Putting feedback string
       fputs(temp.mark, individual_file);
       //putting mark string
       fputs("Comments: ", individual_file);
       //putting "Comments: "
       int j;
       for (j = 0; j <= i; j++)
       {
           if (strlen(temp.comments[j]) > 3)
           {
               fputs(" ", individual_file);
               fputs(temp.comments[j], individual_file);
           }
       }
       fclose(individual_file);
   }
   return 0;
}