Home > Back-end >  I wrote a piece of code to open the text and the different information to the corresponding string,
I wrote a piece of code to open the text and the different information to the corresponding string,

Time:01-30

# include
# include
# include
Int main (void)
{
The FILE * fp.
Fp=fopen (" access log ", "r +");
/*if(! Fp) {
Printf (" false ");
}
The else {
Printf (" true ");
} */
The fgetc (fp);
Char method [255].
Char IP [255];
Char protocol [255].
Char time [255].
Char add [255];
Int port;
Char page [255].
Int the status;
Char exploer_info [255].
Char key;
Char value;
Fscanf (fp, "% % % % % c c c c c c % d % d % % c", method, IP, protocol, time, add, port, page, the status, exploer_info, key, value);
Printf (" % s ", method);
Printf (" % s ", IP);
Printf (" % s ", protocol);
Printf (" % s ", time);
Printf (" % s ", add);
Printf (" % d ", the port);
Printf (" % s ", page);
Printf (" % d ", status);
Printf (" % s ", exploer_info);
Printf (" % s ", key);
Printf (" % s ", value);
Struct record
{
Char method [255].
Char IP [255];
Char protocol [255].
Char time [255].
Char add [255];
Int port;
Char page [255].
Int the status;
Char exploer_info [255].
Struct prams
{
Char key [255].
Char value [255].
};
Int prams_cnt;
};
Int fclose (fp) FILE *;
return 0;
}

CodePudding user response:

Is gibberish, coding issues?

CodePudding user response:

The original poster is thoughtful, he wants to just enter data organization structure, alternative machines don't understand,

CodePudding user response:

Fyi:
//NAME: essaie bla bla 
//DIMENSION: 8
//DATA
14 15//1
//2 November 10
//3 6 4
//4 7 13
//5 September 21
//6 19 3
//7 1 5
//8 8 8
//EOF
//
//text file may also contain other content, but the content of the need to use the above

//such as data. TXT:
//NAME: essaie bla bla
//other content
//DIMENSION: 8
//other content
//DATA
//other content
14 15//1
//other content
//2 November 10
//other content
//3 6 4
//other content
//4 7 13
//other content
//5 September 21
//other content
//6 19 3
//other content
//7 1 5
//other content
//8 8 8
//other content
//EOF

//goal is to get the NAME string, after after DIMENSION values, and the DATA of the following numerical
//which NAME is literally a words, DIMENSION is a number of cities, the DATA below is city number, coordinates X, Y coordinates
//all of these will be assigned to a previously defined structure
#include
#include
# define MAXCPL/80/maximum number of characters per line
100//# define MAXCITY DATA in each set of DATA the multiple number, DIMENSION of the maximum
32//# define MAXNAMEL NAME maximum length
Struct S {
Char NAME [MAXNAMEL + 1];
Int DIMENSION;
Struct D {
Int NO;
Int X;
Int Y;
} DATA [MAXCITY];
} s;
The FILE * f;
Int st, n, I;
Char ln [MAXCPL];
Int main () {
F=fopen (" data. TXT ", "r");
If (NULL==f) {
Printf (" Can not open the file data. TXT! \n");
return 1;
}
St=0;
N=0;
While (1) {
If (NULL==the fgets (ln, MAXCPL, f)) break;
If (st==0) {
If (1==sscanf (ln, "NAME: % 31 [^ \ n]", s.N AME)) st=1;
} else if (st==1) {
If (1==sscanf (ln, "DIMENSION: % d", & amp; Spyware doctor IMENSION st=2));
} else if (st==2) {
If (0==STRCMP (ln, "DATA \ n")) st=3;
{} else if (st==3)
If (3==sscanf (ln, "% d % d % d", & amp; Spyware doctor ATA [n]. NO, & amp; Spyware doctor ATA [n]. X, & amp; Spyware doctor ATA [n]. Y)) {
n++;
If (n>=MAXCITY | | n>=s.d. IMENSION) break;
}
}
}
The fclose (f);
Printf (" s.N AME=] [% s \ n ", s.N AME);
Printf (" s.d. IMENSION=% d \ n ", s.d. IMENSION);
For (I=0; IPrintf (" spyware doctor ATA [% d] NO, X, Y=% d, % d, % d \ n ", I, s.d. ATA [I] NO, s.d. ATA [I] X, s.d. ATA [I] Y);
}
return 0;
}
//s.N AME=[essaie bla bla]
//spyware doctor IMENSION=8
//spyware doctor ATA [0]. NO, X, Y=1,14,15
//spyware doctor ATA [1]. NO, X, Y=2,11,10
//spyware doctor ATA [2]. NO, X, Y=3,6,4
//spyware doctor ATA [3]. NO, X, Y=4,7,13
//spyware doctor ATA [4]. NO, X, Y=5,9,21
//spyware doctor ATA [5]. NO, X, Y=6,19,3
//spyware doctor ATA [6]. NO, X, Y=7,1,5
//spyware doctor ATA [7]. NO, X, Y=8,8,8

  • Related