Home > Software engineering >  MFC in how to extract data from the text in the edit box?
MFC in how to extract data from the text in the edit box?

Time:09-27

Project to do recently, I'm new in MFC, encounter a problem, as shown in figure 1, how to from already saved in MFC good TXT text extracted digital (note is formula), the edit box in figure 2?
Figure 1.
Figure 2.

CodePudding user response:

CFile class readstring read line by line
Separation of each row in front of the name and number
Isolate the Numbers on the controls

CodePudding user response:

Sscanf (readline, "% s % s", prjName, prjValue)
Done!

To filter out the first line!!!!!!

CodePudding user response:

reference 1st floor jacksonfan response:
CFile class readstring read line by line
Separation of each row in front of the name and number
Numbers on the isolated control

How to separate the words and Numbers? I use readString read before, but not separated, please advise,

CodePudding user response:

refer to the second floor shenyi0106 response:
sscanf (readline, "% s % s", prjName, prjValue)
Done!

To filter out the first line!!!!!!

Use this function, the readline is read line by line? Predecessors can give an example?

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

CodePudding user response:

Have been solved, thank you for your help
  • Related