First commit, everything finished and ready.

This commit is contained in:
Ricardo
2022-05-28 00:30:18 +00:00
parent 441f79afe4
commit bc0099c013
6 changed files with 220 additions and 0 deletions

43
functions.c Normal file
View File

@@ -0,0 +1,43 @@
#include <main.h>
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;
}
int invert_file(void) {
if ((info.fd= fopen(info.filename, "r")) != NULL){
int ft, i = 0;
fseek(info.fd, 0, SEEK_END);
ft = ftell(info.fd);
while(i < ft)
{
i++;
fseek(info.fd, -i, SEEK_END);
printf("%c", fgetc(info.fd));
}
printf("\n");
fclose(info.fd);
}
else {
perror(info.filename);
}
return 0;
}