Home > Back-end >  C language error storage size of 'rec' isn 't known
C language error storage size of 'rec' isn 't known

Time:02-24

An error storage size of 'rec' isn 't known
Tried in struct record rec a former added to rec use int or double or char statement, but useless, also complains, as the chart

# include
# include
Int main (void)
{
The FILE * fp.
Fp=fopen (" access log ", "r +");//open the file
if(! Fp)
{
Printf (" false \ n ");
return -1;//return directly
}
The else {
Printf (" true \ n ");
}//to determine whether a file successfully open the
Char line [2048].
Int x, j, j_pos j_pos1;
Int lines=0;
Int pos [9], pos1 [9].
Char s='['
Char s1='] ';
Struct record rec.
While ((the fgets (line, 2048, fp))!=NULL)
{
X=strlen (line);
J_pos=0, j_pos1=0;
For (j=0; J{
If (line [j]==s)
{
Pos [j_pos]=j;
J_pos + +;
}
If (line [j]==s1)
{
Pos1 [j_pos1]=j;
J_pos1 + +;
}
}
}
Strncpy_s (rec) method, sizeof (rec) method), the line + pos [0] + 1, pos1 [0] - pos [0] - 1);
Strncpy_s (rec. IP, sizeof (rec) IP), the line + pos [1] + 1, pos1 [1] - pos [1] - 1);
Strncpy_s (rec) protocol, sizeof (rec) protocol), line + pos [2] + 1, pos1 [2] - pos [2] 1);
Strncpy_s (rec) time, sizeof (rec) time), the line + pos [3] + 1, pos1 [3] - pos [3] - 1);
Strncpy_s (rec. Add, sizeof (rec. Add), line + pos [4] + 1, pos1 [4] - pos [4] - 1);
Strncpy_s (rec) page, sizeof (rec) page), line + pos [5] + 1, pos1 [5] - pos [5] 1);
Strncpy_s (rec) port, sizeof (rec) port), the line + pos [6] + 1, pos1 [6] - pos [6] 1);
Strncpy_s (rec) status, sizeof (rec) status), line + pos [7] + 1, pos1 [7] - pos [7] - 1);
Strncpy_s (rec) exploer_info, sizeof (rec) exploer_info), line + pos [8] + 1, pos1 [8] - pos [8] - 1);
If (line [strlen (line) - 1]=='\ n')
{
Lines++;
} int fclose (fp) FILE *;//close the file
return 0;
}

CodePudding user response:

Struct record
{
. Method;
. IP;
. Protocol;
. time;
. The add;
. Page;
. The port;
. status;
. Exploer_info;
};
This is to define a structure type
Record the rec.
Then record types of variables rec
The above... Structure is the type of the variable
  • Related