Last active
August 29, 2015 14:07
-
-
Save FedericoPonzi/4fdb4cca32a1e429f073 to your computer and use it in GitHub Desktop.
Reverse in c.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main( int argc, char **argv ) | |
{ | |
FILE *in_file; | |
char ch; | |
int len; | |
if( 2 != argc ) | |
{ | |
printf("Error: wrong number of arguments."); | |
return 1; | |
} | |
// Apro il file: | |
in_file = fopen(argv[1], "r"); | |
if(NULL != in_file) | |
{ | |
perror("fopen:"); | |
} | |
//Mi sposto alla fine | |
fseek(in_file, 0, SEEK_END); | |
//Trovo il numero di caratteri | |
len = ftell (in_file); | |
fseek(in_file, -1L, SEEK_CUR); | |
while(len > 0) | |
{ | |
ch = fgetc(in_file); | |
fseek(in_file, -2L, SEEK_CUR); | |
printf("%c", ch); | |
len--; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment