Skip to content

Instantly share code, notes, and snippets.

@JonathonAnderson
Created June 25, 2020 19:45
Show Gist options
  • Save JonathonAnderson/35cbfa1195e5db65e7195017665a75d0 to your computer and use it in GitHub Desktop.
Save JonathonAnderson/35cbfa1195e5db65e7195017665a75d0 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(int argc, char* argv[])
{
FILE *fpt;
char byte;
long int where,move;
if(argc != 2)
{
printf("Usage: fileseek filename\n");
return(0);
}
fpt = fopen(argv[1], "r");
if(fpt == NULL)
{
printf("Unable to open file %s for reading\n", argv[1]);
return(0);
}
while(1)
{
where = ftell(fpt);
fread(&byte,1,1,fpt);
fseek(fpt,-1,SEEK_CUR);
printf("Byte %d: %d (%c)\n", where, byte, byte);
printf("Enter #bytes (+ or -) to move, or 0 to quit: ");
scanf("%d", &move);
printf("move: %d\n", move);
if(move == 0)
break;
fseek(fpt,move,SEEK_CUR);
}
fclose(fpt);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment