From 101dd376b32c2cd12640e81b93c2f30975baac7f Mon Sep 17 00:00:00 2001 From: Joursoir Date: Mon, 26 Oct 2020 19:11:16 +0000 Subject: feature: edit command --- easydir.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'easydir.c') diff --git a/easydir.c b/easydir.c index 08cac0f..9337fe1 100644 --- a/easydir.c +++ b/easydir.c @@ -42,3 +42,37 @@ int checkFileExist(char *path_to_file) return 1; } + +char *fileCropLineFeed(char *path, char *text, int maxlen) +{ + FILE *file = fopen(path, "r+"); + if(file == NULL) callError(130); + + int symbol; + int pos = 0; + char *str = (char *) malloc(sizeof(char) * maxlen); + while((symbol = fgetc(file))) + { + switch(symbol) + { + case '\n': + case EOF: { + str[pos] = '\0'; + pos = -1; // for break while + break; + } + default: { + str[pos] = symbol; + pos++; + break; + } + } + if(pos == -1) break; + if(pos > maxlen-1) { str[pos-1] = '\0'; break; } + } + fclose(file); + + strcpy(text, str); + free(str); + return text; +} -- cgit v1.2.3-18-g5258