Home > Software engineering >  MFC how to read data from the TXT and display in the edit box
MFC how to read data from the TXT and display in the edit box

Time:11-03



How to print the first two lines in the edit box, between column a \ t

CodePudding user response:

The FILE * fp=fopen (); Read the data, and then save as cstrings, can be assigned to the edit box, there may be more simple method, I pure rookie,

CodePudding user response:

Can you explain it detailed said? It's better if with the code, I am pure novices

CodePudding user response:

CTRL + c CTRL + v

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: % 32 [^ \ 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