Category : Files from Magazines
Archive   : CUJ9204.ZIP
Filename : 1004108A

 
Output of file : 1004108A contained in archive : CUJ9204.ZIP

Listing 6
************


struct rec {
char name[31];
char address[21];
char city[16];
char state[3];
char zip[6];
};
static int field_sizes[] = {31, 21, 16, 3, 6};
/*
Alternatively, this could be written as:

static int field_sizes[] = { sizeof(rec.name),
sizeof(rec.address),
...
};
*/
#define field_count (sizeof(field_sizes)/sizeof(int));

main()
{
char record_in[MAX];
struct rec record;
...
while(fgets(record_inn, MAX, filin) != NULL)
{
load_struct(&record, record_in, field_sizes,
field_count, TRUE);
print_struct(&record, field_sizes, field_count, TRUE);
...
}
}

print_struct(record, field_sizes, field_count, nul_terminated)
char *record; /* Record to print */
int field_sizes[]; /* Size of fields */
int field_count; /* Number of fields */
int nul_terminated; /* If fields are nul terminated */
{
int field;
int length;
char *pc;

printf("\n");
pc = record;
for (field = 0; field < field_count; field++)
{
if (nul_terminated)
printf("%s:",pc);
else
{
length = field_sizes[field];
printf("%.*s:", length, pc);
}
pc += field_sizes[field];
}
}

load_struct(record, record_in, field_sizes, field_count,
nul_terminated)
char *record;
char *record_in;
int field_sizes[];
int field_count;
int nul_terminated; /* If fields out should be nul terminated */
{
int field;
int length;
char *pc;
char *pc_in;

pc = record;
pc_in = record_in;
for (field = 0; field < field_count; field++)
{
length = field_sizes[field];
strncpy(pc, pc_in, length);
if (nul_terminated)
{
pc[length-1] = '\0';
pc_in += length - 1;
}
else
pc_in += length;
pc += field_sizes[field];
}
}
********



  3 Responses to “Category : Files from Magazines
Archive   : CUJ9204.ZIP
Filename : 1004108A

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/