First commit, everything finished and ready.
This commit is contained in:
43
functions.c
Normal file
43
functions.c
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user