Guys I need some help to finish this file in sorting. The names need to be sorted in ascending order by the last name.Help
/* GIVEN A TEXT FILE WITH THE APPROPRIATE CONTENTS, READ THE INFORMATION
IN THE FOLLOWTING STRUCTURE (FIGURE); THEN, SORT THE NAMES IN ALPHABETICAL
ORDER ACCORDING TO THE LAST NAME, AND PRINT THE RESULTS IN ANOTHER FILE.
INPUT FILE: IN_INFO.TXT
OUTPUT FILE: OUT_INFO.TXT
__
*/
// *********** Preprocessor Directives ******************************
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
typedef struct
{
char x[70];
float g[4];
} GRADES;
// ************************************************** ****************
// *********** Main Function ****************************************
int main(void)
{
char temp[70];
char temporary[70];
int count, i, j;
FILE *fp1;
FILE *fp2;
FILE *fp3;
GRADES **p;
GRADES **tempString;
p = (GRADES **) calloc(15, sizeof(GRADES *));
fp1 = fopen("in_info.txt", "r");
if (fp1==NULL)
{
printf("Error: can't open input file\n");
exit(1);
}
for (count = 0; count < 15; count++)
{ p[count] = (GRADES *) malloc(sizeof(GRADES));
}
for (i = 0; i < 15; i++)
{
fscanf(fp1, "%s", p[i]->x);
fscanf(fp1, "%s", temp);
strcat(p[i]->x, " ");
strcat(p[i]->x, temp);
for(j = 0; j < 4; j++)
{
fscanf(fp1, "%s", temp);
if (temp[0] == 'W')
{
p[i]->g[j] = 87.0;
}
else {
p[i]->g[j] = atof(temp);
}
}
}
fclose(fp1);
fp2 = fopen("out_info.txt", "w")
for (i = 0; i < 15; i++)
{
fprintf(fp2, "%s ", p[i]->x)
for (j = 0; j < 4;j++)
{
if(p[i]->g[j] == 87.0)
{
fprintf(fp2, "%c ", 'W');
}
else
}
fprintf(fp2, "%3.1f ", p[i]->g[j]);
}
fprintf(fp2, "\n");
}
fclose(fp2);
fp3 = fopen("out_info2.txt", "w");
for (i = 0; i < 15; i++)
{
for(j = i + 1; j < 15; j++)
{
if(strcmp (p[i], p[j]) > 0)
{
tempString = p[i];
p[i] = p[j];
p[j] = tempString;
}
}
fprintf(fp3, "%s", p[i]);
}
return 0;
}