Question
I have a program reading in a text file and sorting the array into a name and age array. I need to use quicksort to
I have a program reading in a text file and sorting the array into a name and age array. I need to use quicksort to sort the name array alphabetically and keep age sorted with it. I cannot use structs. I am having a very hard time, please help. The array to be sorted is name_array. The text file is pasted at the bottom of the page as formatted.
#include
#include
#include
#define LINEBUFF 50;
//Function Prototypes
int main(void) {
//GET ALL OF FILE INPUT AND READING INTO FUNCTION *********
//opens input file as read only
FILE *inp;
inp = fopen("InputData.txt","r");
//Creates 2D array [lines][char's in each line]
char unformatted_line[70][40];
//Writes each line to 2D array
int counter;
int counter2;
for(counter=0; counter<69; counter++)
{
fgets(unformatted_line[counter],40,inp);
}
char last_name[20]={0};
char first_name_1[20]={0};
char first_name_2[20]={0};
char total_name[60]={0};
char age[4]={0};
char name_array[70][40]={0,0};
char age_array[70][4]={0,0};
/*sscanf(unformatted_line[5],"%s %s %s %s", last_name, first_name_1, first_name_2, age);
printf(" %s %s %s %s", last_name, first_name_1, first_name_2, age);
int brak;
scanf("%d",&brak);
printf(" ");
printf("registered ");*/
int iteration=0;
int x=0;
//68 names to iterate through
while(x<68)
{
//printf("%s",unformatted_line[0]);
int total_gap=0;
char *p_un=unformatted_line[iteration];
char *p_un2=unformatted_line[iteration];
//Counts spaces and tabs- tested, correct
//Checks the string for a substring "tab" or " " repeatedly until a null is returned at the ened of the line
while ((p_un=strstr(p_un,"\t")) != NULL)
{
p_un++;
total_gap++;
}
while ((p_un2=strstr(p_un2," ")) != NULL)
{
p_un2++;
total_gap++;
}
//printf("%d", total_gap);
total_name[0] = '\0';
if(total_gap == 2)
{
sscanf(unformatted_line[iteration],"%s %s %s", last_name, first_name_1, age);
strcat(total_name, last_name);
strcat(total_name, " ");
strcat(total_name, first_name_1);
strcpy(name_array[iteration], total_name);
strcpy(age_array[iteration], age);
//printf(" %s",name_array[iteration]);
//printf(" %s",age_array[iteration]);
}
if(total_gap == 3)
{
sscanf(unformatted_line[iteration],"%s %s %s %s", last_name, first_name_1, first_name_2, age);
strcat(total_name, last_name);
strcat(total_name, " ");
strcat(total_name, first_name_1);
strcat(total_name, " ");
strcat(total_name, first_name_2);
strcpy(name_array[iteration], total_name);
strcpy(age_array[iteration], age);
//printf(" %s",name_array[iteration]);
//printf(" %s",age_array[iteration]);
}
x++;
iteration++;
}
return 0;
}
Last Name First Name Age
Karki Bimal Bikram 42
Ramirez Aaron 36
Carroll Ti'ara 54
Huynh Khang 68
Lagares Hunter 72
West Cody 59
Owens Hunter 90
Cleveland Demetrius 5
Urech Thomas 59
Justus Boston 28
Boone Evan 80
Williams Phillip 18
Wilkinson Drew 93
Flores Ryan 12
Bartley Anna 36
Lynskey Ethan 84
Anaghara Ebubechukwu 37
Caon Cristiano Eleutherio 50
Bakliwal Gautam 27
Kiros Michael 8
Quintanilla Emily 7
Chanthavisouk Armon 27
Goonie Rajeev 19
Milestone William 89
Michell Brian 25
Anand Aishwarya Dhirendrakumar 0
McFarlane Scott 94
Palting Faus 73
Vermillion Jason 74
McDougal Luke 43
Vrbas Ryan 69
Anderson Eric 43
Norman Caden 27
Dichiara Michael 79
Ybarra Alexa 29
Costanzo Gabriel 41
Nag Trisha 75
Ferradas Bertoli Nicolas 6
Garrett Will 83
Herrington Dawson 81
Nguyen Chien 76
Bernstein Matt 95
Olson Tommy 11
Kulkarni Adeetya Prashant 48
Harper Andrew 39
Hart Dakota 72
Santana Eric 18
Wagner Madeleine 13
Babatunde Tito 17
Epstein Jameson 59
Pinheiro Angelo 29
Varona Rafael 22
Stephens Daniel 24
Saeed Haroon 23
Fischer Benjamin 3
Oviedo Jose 26
Sieck Blaine 75
Park John 63
Gonzalez Tanya 85
Kalra Saransh 62
Wilson Trent 85
Mireles Erik 11
Richard Darius 4
Pratt Noah 76
Armstrong Micaela 87
Cruz Marco 33
Mendoza Jacob 53
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