Home > Back-end >  Program error, change wrong, can you help me take a look at how to change
Program error, change wrong, can you help me take a look at how to change

Time:02-23

For subsequent request is to analyze the status code access statistics, calculating the ratio of all access status code, so I just defines a lot of array, may be an error in the group in walking down there? Compile a hard, just checked data array subscript the problem might be illegal, who teach me
# 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].//definition and initialization string
Int n=0, m=0;
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 (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
}//output log file content and statistical count
Printf (" % f ", * 1.0 m/n);//output percentage
Int arr [1000]={0};
Int vis [1000]={0};
int i;
for(i=0; i{
Arr [line [I], status] + +;
Vis [line [I], status]=1;
}
Int fclose (fp) FILE *;//close the file
return 0;
}

CodePudding user response:

 for (I=0; i{
Arr [line [I], status] + +;
Vis [line [I], status]=1;
}
In

How to understand this?
The line array name, I & lt; What's the line,
Line [I], the status of this as a subscript and commas, then the status is array name,

Such code is not in conformity with the rules of grammar, naturally prompt compiler error,

CodePudding user response:

The
reference 1/f, confident boy reply:
 for (I=0; i{
Arr [line [I], status] + +;
Vis [line [I], status]=1;
}
In

How to understand this?
The line array name, I & lt; What's the line,
Line [I], the status of this as a subscript and commas, then the status is array name,

Such code is not conform to the rules of grammar will prompt compiler error,

I put the correct line to the line after the [I], the program's warning, but behind the status don't know how to change

CodePudding user response:

refer to the second floor SSyeah response:
Quote: reference 1/f, confident boy reply:
 for (I=0; i{
Arr [line [I], status] + +;
Vis [line [I], status]=1;
}
In

How to understand this?
The line array name, I & lt; What's the line,
Line [I], the status of this as a subscript and commas, then the status is array name,

Such code is not conform to the rules of grammar will prompt compiler error,

I put the correct line to the line after the [I], warning did not have the program, but behind the status don't know how to change the

How to change, want to see what you want to achieve, what is the status for, besides the above didn't assign the status

CodePudding user response:

reference 3 building self-confidence boy reply:
Quote: refer to the second floor SSyeah response:
Quote: reference 1/f, confident boy reply:
 for (I=0; i{
Arr [line [I], status] + +;
Vis [line [I], status]=1;
}
In

How to understand this?
The line array name, I & lt; What's the line,
Line [I], the status of this as a subscript and commas, then the status is array name,

Such code is not conform to the rules of grammar will prompt compiler error,

I put the correct line to the line after the [I], warning did not have the program, but behind the status don't know how to change the

How to change, want to see what you want to achieve, what is the status for, besides the above also not yet assign status

# 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].//definition and initialization string
Int n=0, m=0;
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]={};
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].
Int the status;
Char exploer_info [255].
Struct prams
{
Char key [255].
Char value [255].
};
Char prams_cnt [255].
};//the string in the structure of


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
}//output log file content and statistical count
Printf (" \ n % f ", * 1.0 m/n);//output percentage
Char arr [1000]={0};
Char vis [1000]={0};
int i;
for(i=0; i{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related