Question: any help is much more appreciated the program prints the list of names sorted by last name but what can i add to print names

any help is much more appreciated

the program prints the list of names sorted by last name

but what can i add to print names sortd by first name (first name last name)

#include #include #include

#define MAX_LEN 100 // Length of each line in input file.

int main(void) { char *strFileName = "C:\\Users\\INTEL\\Desktop\\projects\\abc.txt"; char *strFileSummary = "C:\\Users\\INTEL\\Desktop\\projects\\abc1.txt"; char strTempData[MAX_LEN]; char **strData = NULL; // String List int i, j; int noOfLines = 0;

FILE * ptrFileLog = NULL; FILE * ptrSummary = NULL;

if ( (ptrFileLog = fopen(strFileName, "r")) == NULL ) { fprintf(stderr,"Error: Could not open %s ",strFileName); return 1; } if ( (ptrSummary = fopen(strFileSummary, "a")) == NULL ) { fprintf(stderr,"Error: Could not open %s ",strFileSummary); return 1; }

// Read and store in a string list. while(fgets(strTempData, MAX_LEN, ptrFileLog) != NULL) { // Remove the trailing newline character if(strchr(strTempData,' ')) strTempData[strlen(strTempData)-1] = '\0'; strData = (char**)realloc(strData, sizeof(char**)*(noOfLines+1)); strData[noOfLines] = (char*)calloc(MAX_LEN,sizeof(char)); strcpy(strData[noOfLines], strTempData); noOfLines++; } // Sort the array. for(i= 0; i < (noOfLines - 1); ++i) { for(j = 0; j < ( noOfLines - i - 1); ++j) { if(strcmp(strData[j], strData[j+1]) > 0) { strcpy(strTempData, strData[j]); strcpy(strData[j], strData[j+1]); strcpy(strData[j+1], strTempData); } } } // Write it to outfile. file. for(i = 0; i < noOfLines; i++) fprintf(ptrSummary,"%s ",strData[i]); // free each string for(i = 0; i < noOfLines; i++) free(strData[i]); // free string list. free(strData); fclose(ptrFileLog); fclose(ptrSummary); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!