+1 480 409 0818 

Deleting, Interchanging, and Printing Data in C

p4.c #include #include #include #define MAXCHARS 79 typedef struct { char **uniqueLines; int ul; char **dupLines; int dl; int changed; } Record; void removeUniqueLine(Record *r, int i) { free(r->uniqueLines[i]); if (r->ul > i+1) { r->uniqueLines[i] = r->uniqueLines[r->ul-1]; } r->ul--; r->uniqueLines = realloc(r->uniqueLines, r->ul * (2 * MAXCHARS + 1) * sizeof(char)); } void addUniqueLine(Record *r, char* line) { r->ul++; r->uniqueLines = realloc(r->uniqueLines, r->ul * (2 * MAXCHARS + 1) * sizeof(char)); r->uniqueLines[r->ul-1] = line; } void addDupLine(Record *r, char* line) { r->dl++; r->dupLines = realloc(r->dupLines, r->dl * (2 * MAXCHARS + 1) * sizeof(char)); r->dupLines[r->dl-1] = line; } void addLineToRecord(Record *r, char *line, int changed) { r->changed = r->changed > changed ? r->changed : changed; for (int i = 0; idl; i++) { if (strcmp(r->dupLines[i], line) == 0) { return; } } for (int i = 0; iul; i++) { if (strcmp(r->uniqueLines[i], line) == 0) { removeUniqueLine(r, i); addDupLine(r, line); return; } } addUniqueLine(r, line); } void printUniqueLines(Record *r) { for (int i = 0; iul; i++) { printf("%s\n", r->uniqueLines[i]); } } void printDupLines(Record *r) { for (int i = 0; idl; i++) { printf("%s\n", r->dupLines[i]); } } void freeRecord(Record *r) { for(int i = 0; iul; i++) { free(r->uniqueLines[i]); } for(int i = 0; idl; i++) { free(r->dupLines[i]); } free(r->uniqueLines); free(r->dupLines); free(r); } Record *readText(FILE *f) { Record *record = (Record *)malloc(sizeof(Record)); int notFinished = 1; while (notFinished){ char *line = (char *)calloc(2*MAXCHARS, sizeof(char)); int changed = 0; int curr = 0; for (int i = 0; i= 'A' && c <= 'Z') { line[curr] = c + 32; curr++; changed = 1; } else if (c >= 'a' && c <= 'z') { line[curr] = c - 32; curr++; changed = 1; } else if (c == ' ') { line[curr] = ' '; curr++; line[curr] = ' '; curr++; changed = 1; } else if (c >= '0' && c <= '9') { changed = 1; } else { line[curr] = c; curr++; } } line[curr] = 0; } return record; } int main(int argc, char** argv) { FILE *f = NULL; int files = 0; int unique = 1; int changed = 0; for (int i = 1; i r->changed ? changed : r->changed; free(r); } } if (files == 0) { Record *r = readText(NULL); if (unique == 1) { printUniqueLines(r); } else { printDupLines(r); } changed = changed > r->changed ? changed : r->changed; free(r); } return changed; }