Got rid of some useless functions and commented all the code

This commit is contained in:
Ricardo
2022-05-30 19:52:15 +00:00
parent 8a1ae2ca1a
commit 90a67543f0
4 changed files with 50 additions and 56 deletions

View File

@@ -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;