disregard my previous snippet...
every time I work with pointers, arrays structures,
it takes me two days to remember the frigging logic
this should work better
the code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifndef VCOPY
#define VCOPY(_V_) \
strncpy(w ## _V_ , r. ## _V_, sizeof(r. ## _V_))
#endif
int k = 10;
int i = 0 ;
FILE *f;
int l;
char **rt = NULL;
char *rb = NULL;
struct rs
{
char seqn[6] ;
char wsp1[1] ;
char tail[73] ;
} r;
char wseqn[7] ;
char wtail[74] ;
int main(int argc, char **argv)
{
/* array of pointers */
rt = (char **) malloc(k * sizeof(char *));
if ( !rt )
{
perror("error allocating rt!\n");
exit(8);
}
f = fopen("dd:INFILE",
"rb,type=record,recfm=fb,lrecl=80");
if ( !f )
{
perror("INFILE open error!\n");
exit(8);
}
while ( ( i < k ) && !feof(f) )
{
/* input buffer to be retained */
rb = (char *) malloc(80 * sizeof(char *));
if ( !rb )
{
perror("error allocating rb!\n");
exit(8);
}
l = fread( rb, 1, 80, f) ;
if ( l == 0 )
break;
/* save the input buffer address */
rt[i] = rb;
i +=1;
}
k = i;
fclose(f);
printf("records (%d)\n",i);
for ( i=0; i < k; i++)
{
memcpy(&r,rt[i],80);
VCOPY(seqn);
printf("<seqn> >%s<\n", wseqn);
VCOPY(tail);
printf("<tail> >%s<\n", wtail);
}
return (0);
}
the input file ( larger than the builtin max )
000100 AAAA
000200 AAAA
000300 AAAA
000400 AAAA
000500 AAAA
000600 AAAA
000700 AAAA
000800 AAAA
000900 AAAA
001000 AAAA
001100 AAAA
001200 AAAA
001300 AAAA
001400 AAAA
001500 AAAA
the result
records (10)
<seqn> >000100<
<tail> >AAAA <
<seqn> >000200<
<tail> >AAAA <
<seqn> >000300<
<tail> >AAAA <
<seqn> >000400<
<tail> >AAAA <
<seqn> >000500<
<tail> >AAAA <
<seqn> >000600<
<tail> >AAAA <
<seqn> >000700<
<tail> >AAAA <
<seqn> >000800<
<tail> >AAAA <
<seqn> >000900<
<tail> >AAAA <
<seqn> >001000<
<tail> >AAAA <
the input file ( smaller than the builtin max)
000100 AAAA
000200 AAAA
000300 AAAA
000400 AAAA
000500 AAAA
000600 AAAA
the result
records (6)
<seqn> >000100<
<tail> >AAAA <
<seqn> >000200<
<tail> >AAAA <
<seqn> >000300<
<tail> >AAAA <
<seqn> >000400<
<tail> >AAAA <
<seqn> >000500<
<tail> >AAAA <
<seqn> >000600<
<tail> >AAAA <