Home > Back-end >  How to contain alphanumeric and symbol file, extract the digital coordinates, and save to TXT file
How to contain alphanumeric and symbol file, extract the digital coordinates, and save to TXT file

Time:11-14

There is a problem many days, read PLT file, read the same way as TXT file, it is concluded that a lot of information, how can you put the PU and PD behind the coordinates of the extracted IN a TXT file as such IN;
VS32, 1;
VS32, 2;
VS32, 3;
VS32, 4;
VS32, 5;
VS32, 6;
VS32, 7;
VS32, 8;
WU0;
PW0.350, 1;
PW0.350, 2;
PW0.350, 3;
PW0.350, 4;
PW0.350, 5;
PW0.350, 6;
PW0.350, 7;
PW0.350, 8;
LT;
SP1.
PU0-1200;
PD1600-1200;
PD1600 1200;
PD0 1200;
PD0-1200;
SP0;

CodePudding user response:

With a semicolon (;) Divided into good children string, and then find the PU, PD at the beginning of the string, intercept after find out the back of the coordinates

CodePudding user response:

The fscanf % * [^ 0-9] % g ok

CodePudding user response:

Doesn't work, it still comes out of the whole thing,
#include
#include
#include
#include

Int main ()
{
FILE *fp;
Char STR [1024] [1024].
char ch;
The FILE * FPT;
FPT=fopen (" C.t xt ", "w");
If ((fp=fopen (" char. PLT ", "r"))==NULL)
{
Perror (" to read ");
The exit (1);
}

while(! The feof (fp))
{
Fscanf (fp, "% * [^ (9) - 9] % d", STR);
While ((ch=fgetc (fp))!=(EOF)
{
Fputc (ch, FPT);
}
Printf (" % s \ n ", STR, FPT);
}
The fclose (fp);
The fclose (FPT);
return 0;
}

CodePudding user response:

Try a regular expression.

CodePudding user response:

Read after advice, '; 'as the separator, segmentation, respectively, and then use STRNCMP comparison, choose the PD or PU, then the use' '(space) segmentation, finally atoi converted to integers, namely the coordinates,

CodePudding user response:

Regular expressions can

CodePudding user response:

Read after advice, '; 'as the separator, segmentation, respectively, and then use STRNCMP comparison, choose the PD or PU, then the use' '(space) segmentation, finally atoi converted to integers, namely coordinates, come to think of the idea, thought of with a semicolon, but the length of each line is not the same, always can only appear the effect of the first line, the following is useless, but did not use STRNCMP comparison, and atoi don't know if it is no use good or no effect, it is empty, and thanks for your remind

CodePudding user response:

refer to 7th floor lwd2wl response:
Suggestions after reading, to '; 'as the separator, segmentation, respectively, and then use STRNCMP comparison, choose the PD or PU, then the use' '(space) segmentation, finally atoi converted to integers, namely coordinates, come to think of the idea, thought of with a semicolon, but the length of each line is not the same, always can only appear the effect of the first line, the following is useless, but did not use STRNCMP comparison, and atoi don't know if it is no use good or no effect, it is empty, and thanks for your remind


Then each read a fixed length, if not read completely, can consider to put this line the last; On the next line,

CodePudding user response:

Fscanf will support simple regular

CodePudding user response:

Thank you, has been written

CodePudding user response:

PW instruction in PLT file is what meaning??
  • Related