Loading file_operations.cdeleted 100644 → 0 +0 −42 Original line number Diff line number Diff line // // Created by mburket on 2/28/18. // #include "file_operations.h" #include "string.h" /// This method gets the last /// /// \param path /// \param output /// \return int get_last_line(char *path, char *output) { char *currentLine = malloc(BUFFSIZE); char *lastLine = malloc(BUFFSIZE); FILE *fp = fopen(path, "r"); while (fgets(currentLine, BUFFSIZE, fp)) { lastLine = strcpy(lastLine, currentLine); } strcpy(output, lastLine); free(lastLine); free(currentLine); } int get_specific_line(char *path, char *output, int finalLine) { char *currentLine = malloc(BUFFSIZE); char *lastLine = malloc(BUFFSIZE); FILE *fp = fopen(path, "r"); int line = 1; while (fgets(currentLine, BUFFSIZE, fp)) { lastLine = strcpy(lastLine, currentLine); if (line == finalLine) { break; } line++; } strcpy(output, lastLine); free(lastLine); free(currentLine); } file_operations.hdeleted 100644 → 0 +0 −15 Original line number Diff line number Diff line // // Created by mburket on 2/28/18. // #ifndef COMS352_SHELL_FILE_OPERATIONS_H #define COMS352_SHELL_FILE_OPERATIONS_H #include <stdio.h> #include <stdlib.h> #define BUFFSIZE (sizeof(char) * 5000) int get_last_line(char *path, char *output); int get_specific_line(char *path, char *output, int finalLine); #endif //COMS352_SHELL_FILE_OPERATIONS_H Loading
file_operations.cdeleted 100644 → 0 +0 −42 Original line number Diff line number Diff line // // Created by mburket on 2/28/18. // #include "file_operations.h" #include "string.h" /// This method gets the last /// /// \param path /// \param output /// \return int get_last_line(char *path, char *output) { char *currentLine = malloc(BUFFSIZE); char *lastLine = malloc(BUFFSIZE); FILE *fp = fopen(path, "r"); while (fgets(currentLine, BUFFSIZE, fp)) { lastLine = strcpy(lastLine, currentLine); } strcpy(output, lastLine); free(lastLine); free(currentLine); } int get_specific_line(char *path, char *output, int finalLine) { char *currentLine = malloc(BUFFSIZE); char *lastLine = malloc(BUFFSIZE); FILE *fp = fopen(path, "r"); int line = 1; while (fgets(currentLine, BUFFSIZE, fp)) { lastLine = strcpy(lastLine, currentLine); if (line == finalLine) { break; } line++; } strcpy(output, lastLine); free(lastLine); free(currentLine); }
file_operations.hdeleted 100644 → 0 +0 −15 Original line number Diff line number Diff line // // Created by mburket on 2/28/18. // #ifndef COMS352_SHELL_FILE_OPERATIONS_H #define COMS352_SHELL_FILE_OPERATIONS_H #include <stdio.h> #include <stdlib.h> #define BUFFSIZE (sizeof(char) * 5000) int get_last_line(char *path, char *output); int get_specific_line(char *path, char *output, int finalLine); #endif //COMS352_SHELL_FILE_OPERATIONS_H