Question: I am writing code For C and my program keeps crashing and i cant figure out why. I will be posting the assighment requirments and
I am writing code For C and my program keeps crashing and i cant figure out why.
I will be posting the assighment requirments and the code i have developed for C
Please make my code work and uplead the source code with the text files as will..
Please add comments everywhere so I can follow what you are doing.


//Defined constant variables #define _CRT_SECURE_NO_WARNINGS //Removes Scan Error #define MAX 100
//Included libraries #include
// Main Driver File int main() { //Declare input and output as pointers to a File FILE *input; FILE *output;
//Local Varaibles int i = 0; int count; char s[10];
void sort(struct ID ID1[], int size);
//Open File, read only mode input = fopen("input.txt", "r");
//Crash Protection statment if (!input) { printf("not able to open file for reading "); return -1; }
//Iterative Loop to cycle through ID while (!feof(input)) { fscanf(input, "%s%s%s", identification[i].lastName, identification[i].firstName, s); identification[i].age = atoi(s); i++; }
count = i; sort(identification, count);
//Write Identification to file output = fopen("output.txt", "w");
//Crash Protection statment if (!output) { printf("Not able to open file for writing "); return -1; }
//Itterative statment to record all ID's for (i = 0; i
//Close all files fclose(input); fclose(output); }
//Templet for users Information struct ID { //Arrays are set to a maximum of 20 characters //I am assuming not given name will be larger than 20 char char firstName[20]; char lastName[20]; int age; //I am assuming users will not input decimal values }
identification[MAX];
//Sort using bubble sort void sort(struct ID rec1[], int size) { //Local Variables char s1[20], s2[20]; int ag, i, j, cmp;
//Loop format for a bubble sort for (i = 0; i
if (cmp For this assessment you are to write a C program that reads names and corresponding ages of people records from a file, and then sorts the records based on the person's last name (in descending order). Once the records have been sorted, you must output the sorted records to a different file. You do NOT have to perform error checking on the records You may assume that they are stored in the input file in the appropriate format and alignment as follows (last name, first name age) Ruth, Babe 115 Jordan, Michael 46 Obama, Barack 48 Potter, Harry 16 Favre, Brett 38 Potter, Carrie 40 Hamm, Mia 33 After you have sorted the input records, the output records should be displayed in the output file as follows (with the age first): 115 Ruth, Babe 16 Potter, Harry 40 Potter, Carrie 48 Obama, Barack 46 Jordan, Michael 33 Hamm, Mia 38 Favre, Brett Note: The records were sorted based on last name, not the age! Requirements: The following are the ONLY requirements for the implementation of your solution. Your solution may be implemented in any way (using C) just as long as you have the following: 1. Input file with records stored in the format provided above 2. Output file with the sorted records stored in the format provided above 3. An array of structs, where each cell of the array (which is a struct) contains a record with a last name, first name, and age field, corresponding to the order of the records in the input file
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
