Home > Back-end >  Don't know why can't debugging, can you help me have a look?
Don't know why can't debugging, can you help me have a look?

Time:02-25

Is dev - c + + compiler, transferred to 64 - bit debug mode, operation result is wrong, will pop up a window to debug, debug is down again, can you help me have a look at where went wrong?
# include
# include
Struct record//record for structure name
{
Char method [255].
Char IP [255];
Char protocol [255].
Char time [255].
Char add [255];
Char port [255].
Char page [255].
Int the status;
Char exploer_info [255].
Struct prams
{
Char key [255].
Char value [255].
};
Int prams_cnt;
};//define structure
Int main (void)
{

//struct record rec.
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;
Int pos [9], pos1 [9].
Char s='['
Char s1='] ';
Struct record rec.//structure variables
Printf (" log analysis: \ n ");
Int n=0, m=0;
While (the fgets (line, 2048, fp)!=NULL)
{
Puts (line);
N++;
If (STRNCMP (line, "[GET]", 5)==0)
{
m++;
}//compare two strings, equal STRNCMP function value returns 0, count
}

Printf (" proportion of output GET request: % f \ n ", 1.0 * m/n);//output percentage;
Struct record items [255].//all records
Int items_cnt=0;//record number

//output log file content and statistical count

Char arr [1000]={0};
Char vis [1000]={0};
for(i=0; i{
Arr [items [I] the status] + +;
Vis [items [I] the status]=1;
}

Printf (" % d ", 1.0 * arr [I] + +/I).
Int maxi=0, maxn=0;
for(i=0; i{
If (maxn{
Maxn=vis [I];
Maxi=I;
}
}
While ((the fgets (line, 2048, fp))!=NULL)
{
X=strlen (line);
J_pos=0, j_pos1=0;
for(j=0; J{
If (line [j]==s)//here for '[' to begin the location of the
{
Pos [j_pos]=j;
J_pos + +;
}
If (line [j]==s1)//'] 'the location of the end of the
{
Pos1 [j_pos1]=j;
J_pos1 + +;
}
}
}
//strncpy_s function using strncpy_s (char * str2, int size2, char * str1, int size1);
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);
//structure members assignment
i++;
If (line [strlen (line) - 1]=='\ n')
{
Lines++;
}



Int fclose (fp) FILE *;//close the file
return 0;
}

CodePudding user response:

This is commonly pointer exception, you step through the breakpoint to the main function to start the first sentence, step by step

CodePudding user response:

Didn't scan your code, but because the data read from the file, save the data and are all fixed. Small array, unless you file content is small or relatively fixed, an array of the risk is too big
  • Related