home *** CD-ROM | disk | FTP | other *** search
- /*
- * get_nth_string.c Brian Rice rice@dg-rtp.dg.com 1989
- * This routine is part of the shop package.
- * It takes advantage of the fact that the first sizeof(long) bytes
- * in the file named by f are a long which gives the number of
- * items in that file.
- */
-
- #include <stdio.h>
- #include "shop.h"
-
- char *get_nth_string(f,n,buff,l)
- FILE *f;
- long int n;
- char *buff;
- int l;
- {
- long int begin_loc, end_loc;
- int s_length;
-
- (void) fseek(f,n*BYTE_COUNT_SIZE+ITEM_COUNT_SIZE,0);
- (void) fread(&begin_loc,sizeof begin_loc,1,f);
- (void) fread(&end_loc,sizeof end_loc,1,f);
-
- s_length = end_loc - begin_loc;
-
- if (s_length > l - 1)
- s_length = l - 1;
-
- (void) fseek(f,begin_loc,0);
-
- (void) fread(buff,sizeof(char),s_length,f);
-
- buff[s_length] = '\0';
-
- return buff;
- }
-
-