+1 (315) 557-6473 

Processing Input Data in C assignment help

The task required the implementation of a single-file C program which must provide the following functionality. Our C programming assignment help solvers create an application that reads from the standard input char by char and line by line to make some transformations of input: delete all digits, interchange the case of alphabetical letters. Every time space is encountered the program should print two spaces instead of one, printing an only copy of duplicate lines, etc. The application also must change its behavior according to provided command-line arguments.

Table Of Contents
  • Deleting, Interchanging, and Printing Data in C

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; }