Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

structer within structer or array within structer problem

Status
Not open for further replies.

larryfergy

Technical User
Dec 29, 2002
2
US
My input record consistes of a master record (the one that starts with the year) and the indented records that match. My idea was to load this into a structer so that I could later add other records that match to these master records.
1993 miniature Snowy Adventure 2 plate
Snowy Adventure mini plate by Donald Zolan$7.00 Bids 1
Snowy Adventure mini plate by Donald Zolan$7.00 Bids 1
1994 miniature Two of a Kind 1 plate
"Two of a Kind" mini plate by Donald Zolan $7.50 Bids 1
"Two of a Kind" mini plate by Donald Zolan $7.50 Bids 1
1991 miniature Morning Discovery 2 lithograph
Morning Discovery lithograph Donald Zolan $10.99 Bids 2
Morning Discovery lithograph Donald Zolan $10.99 Bids 2

The structer I developed was this

struct tagmom
{
int lineno;
char momsline[80];

struct tagdolan
{
int lineno;
char dolanline[80];
};
};
All the found records for the master record would be in that particular master record. Atleast that is what I thought

The build structer works;

#include <gc.h>
#include <stdio.h>
#include <ctype.h>
#include <assert.h>
#include <time.h>
#include <string.h>
#include <conio.h>



FILE *in1;
FILE *in2;
FILE *in3;
FILE *out1;
char line[80];
char PLATE[15] = {
&quot;PLATE&quot;};
struct tagmom
{
int lineno;
char momsline[80];
struct tagdolan
{
int lineno;
char dolanline[80];
};

};
struct tagmom mymoms[100];
struct tagdolan mydolan[100];
char * Build_Structer(struct tagmom *m,struct tagdolan *d);
int
main(void)
{
char *cp;
char *ip;
char *op;
char *poldcloses;
char *result;
/* GC_malloc(sizeof(struct tagmom)*100);
; */
malloc(sizeof(struct tagmom)*100);
malloc(sizeof(struct tagdolan)*100);

struct tagmom *momsrecs;
momsrecs = mymoms;
struct tagdoln *dolanrecs;
dolanrecs = mydolan;

BuildStructer(momsrecs,dolanrecs);


fclose(in3);
fclose(out1);
return(0);
}
char *
BuildStructer(struct tagmom *mom,struct tagdolan *dolan)
{
char *poldrec;
char oldline[80];
int result;
int momline;
int doline;
char *pmom;
char *pdolan;
int nresult;
momline = 0;
doline = 0;
pmom = &mom;

in3 = fopen(&quot;c:\\lc\\datfiles\\zolan_finds\\oldcloses.txt&quot;, &quot;r&quot;);

poldrec = fgets(restrict oldline,80,in3);
pmom = &mom;

doline = 0;
momline = 0;
/* mom->lineno = 0;
dolan->lineno = 0; */
do
{
do
{
poldrec = fgets(restrict oldline,80,in3);
nresult = isdigit(*poldrec);
}
while(*poldrec == '\n');

strcpy(mom[++momline].momsline,poldrec);
doline= 0;

do
{
poldrec = fgets(oldline,80,in3);
}
while(*poldrec == '\n');
do
{


strcpy(dolan[++doline].dolanline,oldline);
poldrec = fgets(oldline,80,in3);
if (poldrec == NULL)
break;
}
while(*poldrec != '\n');

}
while(poldrec != NULL);
mom->lineno = 1;

result = printf(&quot;\n%s&quot;,mom->momsline);
momline = 1;
doline = 1;
return (mom);
}

The build works. Or looks like it works. But when I reference the structer after the build with a debbugger or printing values have a problem
mom[1].momsline = 1993 miniature Snowy Adventure 2 plate
dolan[1].dolanline = Morning Discovery lithograph Donald Zolan $10.99 Bids 2

The master record is at 1
The found record is at last record

1993 miniature Snowy Adventure 2 plate
Snowy Adventure mini plate by Donald Zolan$7.00 Bids 1
Snowy Adventure mini plate by Donald Zolan$7.00 Bids 1
1994 miniature Two of a Kind 1 plate
&quot;Two of a Kind&quot; mini plate by Donald Zolan $7.50 Bids 1
&quot;Two of a Kind&quot; mini plate by Donald Zolan $7.50 Bids 1
1991 miniature Morning Discovery 2 lithograph
Morning Discovery lithograph Donald Zolan $10.99 Bids 2
Morning Discovery lithograph Donald Zolan $10.99 Bids 2

I also tried this structer

struct tagmom
{
int lineno;
char momsline[80];
char dolanline[100][80];

};
struct tagmom mymoms[100];

But the same thing happens . The build appears to work but the reference later doesn't
 
Everythink is ok. Changed the moved dolanhits from its tagdolan to tagmom structer and made a double level array and that seems to work. It nice to know about this site. I'm sure I'll need it later, but not now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top