Commit f6c17143 authored by Matthew Burket's avatar Matthew Burket

REmove file ops as they are not need. So long.

parent 825ac899
//
// 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);
}
//
// 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment