From 90a67543f0ed6417fcce39025a3674766dd1140d Mon Sep 17 00:00:00 2001 From: Ricardo Date: Mon, 30 May 2022 19:52:15 +0000 Subject: [PATCH] Got rid of some useless functions and commented all the code --- functions.c | 46 +++++++++++++++++++--------------------------- include/main.h | 11 +++++------ inverT | Bin 17632 -> 17600 bytes main.c | 49 ++++++++++++++++++++++++++----------------------- 4 files changed, 50 insertions(+), 56 deletions(-) mode change 100644 => 100755 inverT diff --git a/functions.c b/functions.c index 4be6d72..8898c5f 100644 --- a/functions.c +++ b/functions.c @@ -2,41 +2,33 @@ int ask_file() { - printf ("Insert name of the file to be read : "); - fgets(info.filename, info.fileNameSize, stdin); - info.filename[strlen(info.filename)-1] = '\0'; - invert_file(); - return 0; -} - -int get_file(char *fileName) { - - strcpy(info.filename, fileName); - invert_file(); - return 0; + printf ("Insert name of the file to be read : "); // print this + fgets(info.filename, info.fileNameSize, stdin); // get the file from user input + info.filename[strlen(info.filename)-1] = '\0'; // turn the last character into zero + return 0; // to clear the newline character in there } int invert_file(void) { - if ((info.fd= fopen(info.filename, "r")) != NULL){ - int ft, i = 0; + if ((info.fd= fopen(info.filename, "r")) != NULL){ // If the file opens + int ft, i = 0; // make this two variables to help + // going thru the text + fseek(info.fd, 0, SEEK_END); // take the file descriptor pointer + // to the end of the file + ft = ftell(info.fd); // Count the file total number of characters - fseek(info.fd, 0, SEEK_END); + while(i < ft) { // While the characters dont finish + i++; // increment one character + fseek(info.fd, -i, SEEK_END); // go back one character in the text + printf("%c", fgetc(info.fd)); // print current character + } + printf("\n"); // print newline to clear the terminal - ft = ftell(info.fd); - while(i < ft) - { - i++; - fseek(info.fd, -i, SEEK_END); - printf("%c", fgetc(info.fd)); - } - printf("\n"); - - fclose(info.fd); + fclose(info.fd); // Close the file } - else { - perror(info.filename); + else { // Otherwiser + perror(info.filename); // print failed to open the file } return 0; diff --git a/include/main.h b/include/main.h index a5eab64..5fadbec 100644 --- a/include/main.h +++ b/include/main.h @@ -6,13 +6,12 @@ //Function declarations -int ask_file(); // It has no flags, it just prompts for filename -int get_file(char *fileName); // Gets the filename passed on has an argument -int invert_file(void); // Invert the file stored in the variable info.filename +int ask_file(); // It has no flags, it just prompts for filename +int invert_file(void); // Invert the file stored in the variable info.filename -//This are general parameters for the program -struct parameters { + +struct parameters { //This are general parameters for the program char filename[100]; // Filename where the text is FILE *fd; // File descriptor for the text file @@ -21,6 +20,6 @@ struct parameters { char help[]; // Help menu to be printed on screen }; -struct parameters info; +struct parameters info; // Declare struct info of type parameters #endif diff --git a/inverT b/inverT old mode 100644 new mode 100755 index 1a385373f4d6c9f6a7db48c708dcae5aaf01445e..5f21d97e3a42ccdcef354cd1ada69a0002e2589b GIT binary patch delta 1266 zcmY*ZZD?Cn7(VA_Nz>USHyMKx-F@7c<1Y;<#78xJgmrGxoI@&GOLJ;1izchHaN$r~ScJX?C5I zV1#nP@XjmiU|SJYOCIyizpJXuItf}g(zmRa(4j0!m9Jn!FPA@;rDCwPzaJslRp!qr z5bD`-Ejv-mzF{?p>^`B-x7A0&6*TgO9(DhSQARLfBjKL$jeq{nR;`P|pFdKc-nfh@&wwhQw*?>h z?^d}75-ZlQi1K3`-5C=HW|hD>w-Q6$o9T|f{cr8X%&FZ!bTAgvUf63~(}wpNE86p# zu{Nxq+P(n(K&EqD&sMzF7v{m{bDL>Mk|&in)8g~;!U})db{;rZwe8n{p8($mjxO8w zEKt2;+c$s(;Htp8w%vlaQdVqxluAmxlOdxU3L9*YWk3Sf2Cn{bv&V!4YoS0aen`~6 zF5X)6$?r=8TRg6-ys5#<+CY5>8@+AYuLAGu(#t}2^v^*Tp#SxNe%sMShwou|nu`s% z!{{(;@@@7*BsX+ScBS}~+1K@kn@`dC-e-8xT<*QerQc$7b>|Gv(_6dZ{C7ILYaDtk zIYORfkS`HWM)3=+Tm%>g zACOwuaa9%c{k4Pkry`95^(=*srsB~9!jpVV4yaDty=N@bm#GLpLd%%y9r`5|iGEPe zTdGGo&x)MWPRu!H|BAG}NOYf5vxza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