Home > Back-end >  For bosses to help have a look at what went wrong
For bosses to help have a look at what went wrong

Time:02-24

An error storage size of 'rec' isn 't known


# 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 

This structure declaration in where? Didn't see?

CodePudding user response:

The
reference 1/f, confident boy reply:
 struct record 

This structure declaration in where? Don't see,

Life is an error, and will add error, the original error still exists

CodePudding user response:

Because the IDE does not support strncpy_s () function, so I can't see the results, text annotations, for reference:
 # include 
# include

Struct record//structure
{
Char method [255].
Char IP [255];
Char protocol [255].
Char time [255].
Char add [255];
Char port [255].
Char page [255].
Char status [255].
Char exploer_info [255].
};

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 I=0, x, j, j_pos, j_pos1;//int lines=0;//the variable useless to
Int pos [9], pos1 [9].
Char s='[]', s1=' ';

Struct record rec [4096].//the default file has 4096 lines

While ((the fgets (line, 2048, fp))!=NULL)
{
X=strlen (line);
J_pos=0, j_pos1=0;
For (j=0; J{
If (line [j]==s)//'[' starting position
{
Pos [j_pos]=j;
J_pos + +;
}
If (line [j]==s1)//'] 'end
{
Pos1 [j_pos1]=j;
J_pos1 + +;
}
}
//strncpy_s (char * str2, int size2, char * str1, int size1);//here char * str1, int size1 two values the building their debugging
Strncpy_s (rec [I]. Method, sizeof (rec [I] method), the line + pos [0] + 1, pos1 [0] - pos [0] - 1);
Strncpy_s (rec [I]. IP, sizeof (rec [I]. IP), the line + pos [1] + 1, pos1 [1] - pos [1] - 1);
Strncpy_s (rec [I]. Protocol, sizeof (rec [I] protocol), line + pos [2] + 1, pos1 [2] - pos [2] 1);
Strncpy_s (rec [I]. Time, sizeof (rec [I] time), the line + pos [3] + 1, pos1 [3] - pos [3] - 1);
Strncpy_s (rec [I]. Add, sizeof (rec [I]. Add), line + pos [4] + 1, pos1 [4] - pos [4] - 1);
Strncpy_s (rec [I]. Page, sizeof (rec [I] page), line + pos [5] + 1, pos1 [5] - pos [5] 1);
Strncpy_s (rec [I]. Port, sizeof (rec [I] port), the line + pos [6] + 1, pos1 [6] - pos [6] 1);
Strncpy_s (rec [I]. Status, sizeof (rec [I] status), line + pos [7] + 1, pos1 [7] - pos [7] - 1);
Strncpy_s (rec [I]. Exploer_info, sizeof (rec [I] exploer_info), line + pos [8] + 1, pos1 [8] - pos [8] - 1);
i++;
//if (line [strlen (line) - 1]=='\ n')
//{
//lines++;
//}
}
The fclose (fp);//close the file

//all read in rec [I] in the array, the next processing code to join


return 0;
}
  • Related