Home > Back-end >  Program cannot output, also shows that warning, bosses help have a look
Program cannot output, also shows that warning, bosses help have a look

Time:02-20

I write programs to statistics the number of all the get in the log file and the percentage, but beg a percentage of the a program to output, also shows a warning, checked according to the meaning of this warning is lack of header files, but I can't find where is wrong, please understand person to help see
# include
# include
Int main (void)
{
The FILE * fp.
Fp=fopen (" access log ", "r +");
if(! Fp) {
Printf (" false \ n ");
return -1;//return directly
}
The else {
Printf (" true \ n ");
}
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]={};
Char key [255]={};
Char value [255]={};
Char prams_cnt [255]={};//the string definition and initialization
Struct record
{
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].
Struct prams
{
Char key [255].
Char value [255].
};
Char prams_cnt [255].
};//the string in the structure of
While (getc (fp)!=(EOF)
{
The fgets (method, 1000, fp);
The fgets (IP, 1000, fp);
The fgets (protocol, 1000, fp);
The fgets (time, 1000, fp);
The fgets (add, 1000, fp);
The fgets (port, 1000, fp);
The fgets (page, 1000, fp);
The fgets (status, 1000, fp);
The fgets (exploer_info, 1000, fp);
The fgets (key, 1000, fp);
The fgets (value, 1000, fp);
The fgets (prams_cnt, 1000, fp);
Printf (" % s ", method);
Printf (" % s ", IP);
Printf (" % s ", protocol);
Printf (" % s ", time);
Printf (" % s ", add);
Printf (" % s ", the port);
Printf (" % s ", page);
Printf (" % s ", status);
Printf (" % s ", exploer_info);
Printf (" % s ", key);
Printf (" % s ", value);//the log file output
};
Int I=0, n=0;
for(i=0; i<1000; I++)
{
If (method [I]="[GET]")
{
N++;
}
};
Double pro=0.0;
Pro=1.0 * I/n;
Printf (" % f ", pro);

Int fclose (fp) FILE *;
return 0;
}

CodePudding user response:

 if (method [I]="[GET]") 
this is to determine method [I]=="[GET]?" String should be:
 # include//the header file 
If (STRCMP (method [I], "[GET]")==0)

CodePudding user response:

 # include 
# include

Int main (void)
{
The FILE * fp.
Fp=fopen (" access log ", "r +");
if(! Fp) {
Printf (" false \ n ");
return -1;//return directly
}
The else {
Printf (" true \ n ");
}

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]={};
Char key [255]={};
Char value [255]={};
Char prams_cnt [255]={};//the string definition and initialization

Struct record
{
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].
Struct prams
{
Char key [255].
Char value [255].
};
Char prams_cnt [255].
};//the string in the structure of
While (getc (fp)!=(EOF)
{
/*//possible memory
The fgets (method, 1000, fp);
The fgets (IP, 1000, fp);
The fgets (protocol, 1000, fp);
The fgets (time, 1000, fp);
The fgets (add, 1000, fp);
The fgets (port, 1000, fp);
The fgets (page, 1000, fp);
The fgets (status, 1000, fp);
The fgets (exploer_info, 1000, fp);
The fgets (key, 1000, fp);
The fgets (value, 1000, fp);
The fgets (prams_cnt, 1000, fp);
*/
The fgets (method, sizeof (method), fp);
The fgets (IP, sizeof (IP), fp);
The fgets (protocol, sizeof (protocol), fp);
The fgets (time, sizeof (time), fp);
The fgets (add, sizeof (add), fp);
The fgets (port, sizeof (port), fp);
The fgets (page, sizeof (page), fp);
The fgets (status, sizeof (status), fp);
The fgets (exploer_info, sizeof (exploer_info), fp);
The fgets (key, sizeof (key), fp);
The fgets (value, sizeof (value), fp);
The fgets (prams_cnt, sizeof (prams_cnt), fp);
Printf (" % s ", method);
Printf (" % s ", IP);
Printf (" % s ", protocol);
Printf (" % s ", time);
Printf (" % s ", add);
Printf (" % s ", the port);
Printf (" % s ", page);
Printf (" % s ", status);
Printf (" % s ", exploer_info);
Printf (" % s ", key);
Printf (" % s ", value);//the log file output
}//.
Int I=0, n=0;
/*
for(i=0; i<1000; I++)
{
//if (method [I]="[GET]")
If (STRCMP (method, "[GET]")==0)
{
N++;
}
};
*/
If (STRCMP (method, "[GET]")==0)
{
N++;
}
Double pro=0.0;
Pro=1.0 * I/n;
Printf (" % f ", pro);

Int fclose (fp) FILE *;
return 0;
}


For your reference ~

CodePudding user response:

To do this definition so much clutter, grab a line, compare the top five characters, circulation,
 
# include
# include

Int main (void)
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related