// advanced_linter.c // // Written by YOUR-NAME (YOUR-ZID) // on TODAYS-DATE // // A mini linter that applies multiple formatting transformations to code lines. #include #include #define MAX_LINE_LENGTH 1024 // Your function prototypes void collapse_whitespace(char *line); void add_operator_spacing(char *line); void wrap_long_lines(char *line); // Provided function prototypes void lint_line(char *line); void remove_newline(char *line); // ----------------------------------------------------------------------------- // DO NOT CHANGE THE MAIN FUNCTION int main(void) { char line[MAX_LINE_LENGTH]; printf("Enter lines of code:\n"); while (fgets(line, MAX_LINE_LENGTH, stdin) != NULL) { remove_newline(line); lint_line(line); printf("%s\n", line); } return 0; } // ----------------------------------------------------------------------------- // YOUR FUNCTIONS // ----------------------------------------------------------------------------- // Replace multiple spaces with a single space. void collapse_whitespace(char *line) { // TODO: Implement this function } // Add spaces around operators (= + - * /). void add_operator_spacing(char *line) { // TODO: Implement this function } // Wrap lines longer than 80 characters so that there is at most // 80 characters per line. void wrap_long_lines(char *line) { // TODO: Implement this function } // ----------------------------------------------------------------------------- // PROVIDED FUNCTIONS // ----------------------------------------------------------------------------- // Applies every linting rule in order. void lint_line(char *line) { collapse_whitespace(line); add_operator_spacing(line); wrap_long_lines(line); } // Helper function to remove the newline character from the end of a string void remove_newline(char *line) { // Find the newline or end of string int i = 0; while (line[i] != '\n' && line[i] != '\0') { i++; } // Goto the last position in the array and replace with '\0' // Note: will have no effect if already at null terminator line[i] = '\0'; }