I thought
Code:
strncmp(line, "ENDL", 4)
returns a 1 when the strings are the same. Never mind then.
Instead of printing out the structure every time I scan it, I want to store then in an array of structures. So I'd pass the pointer to the array to a function that will read in all the individual structures. I don't really get how it is explained here:
Code:
struct Node *make_node ( void )
{
struct Node new_node = malloc ( sizeof *new_node );
/* Error check and set a default state */
return new_node;
}
That's from Prelude's FAQ again.
I did it like it makes sense to me:
Code:
int
main (void)
{
int i, j, nExpected, nActual=0;
char Word[25];
FILE* inp;
struct EDFLine *Sec;
..........................
Sec = calloc(nExpected, sizeof (struct EDFLine));
ReadSection(inp, Sec, nExpected, &nActual);
}
int ReadSection(FILE * inp, struct EDFLine Sec[], int nExpected, int*nActual)
{
char line[80];
int i=0;
while ( fgets(line, sizeof line, inp) != NULL )
{
if ( strncmp(line, "ENDL", 4) == 0 )
{
break;
}
if (strncmp(line, "END", 3) != 0)
{
if ( sscanf(line, "%s %d %d %d %d %d", Sec[i].Param, &Sec[i].Label,
&Sec[i].SFactor, &Sec[i].SigBits, &Sec[i].Bit30, &Sec[i].Bit31) == 6)
{
nActual ++;
i++;
}
}
}
if (*nActual == nExpected)
return 1;
else
return 0;
}
Right now it exits the loop right away, again.
Oh, and you guys told me numerously before not to typecast the calloc and never worked for me before. It kept giving me an incompatibility error, but now it worked.....