Skip to content

Instantly share code, notes, and snippets.

@FedericoPonzi
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FedericoPonzi/4fdb4cca32a1e429f073 to your computer and use it in GitHub Desktop.
Save FedericoPonzi/4fdb4cca32a1e429f073 to your computer and use it in GitHub Desktop.
Reverse in c.
#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