|
/* hunt.c ....Sam Bent.... 1/14/88 */
/* browse around a file at random */
#include <stdio.h>
#define MAXLINELENGTH 200
main()
{
char name[50], buffer[MAXLINELENGTH];
FILE *fp;
float percent;
long length, address;
....printf("File
name: ");
....scanf("%s",
name);
....fp = fopen(name,
"r");
....if
(fp==NULL) {
........printf("Can't
open %s\n", name);
........exit(-1);
........}
....fseek(fp, 0, 2);
..../* 2 means offset
from end of file */
....length =
ftell(fp);
....for (;;) {
........printf("Percentage: ");
........scanf("%f",
&percent);
........if
(percent<0) break;
........address =
percent * length / 100;
........fseek(fp,
address, 0); /* offset from beginning */
........while
(getc(fp) != '\n') ; /* skip to end of line */
........address =
ftell(fp);
....v...fgets(buffer,
MAXLINELENGTH, fp);
........printf("0x%06x %s", address,
buffer);
........}
....exit(0);
}
|