Home > Back-end >  C language parsing binary file, remove labels, two numerical after reading labels, write a file
C language parsing binary file, remove labels, two numerical after reading labels, write a file

Time:12-16



Need to remove the label (AA AA 04, 80 02), keep the label after two data, bosses have any ideas? Strives for the code

CodePudding user response:

Really lazy, this is the fixed pattern, accordingly it directly, in accordance with the agreement,

CodePudding user response:

 # include & lt; Stdio. H> 
#include
Int main () {
Unsigned char [24] s={
0 xaa, 0 xaa, 0 x04, 0 x80, 0 x02, 0 x12, 0 x34, 0 x99,
0 xaa, 0 xaa, 0 x04, 0 x80, 0 x02, 0 x56, 0 x78, 0 x99,
0 xaa, 0 xaa, 0 x04, 0 x80, 0 x02, 0 x12, 0 x34, 0 x99,
};
Unsigned char m [5]={x04 xaa 0, 0 xaa, 0, 0 x80, 0 x02};
Unsigned char d [6].
Unsigned char * ps, * pd;

Ps=s;
Pd=d;
While (1) {
If (0==memcmp (ps, m, 5)) {
Pd [0]=ps [5];
Pd [1]=[6] of ps;
Ps +=8;
Pd +=2;
If (ps - s>=24 | | pd - d>=6) break;
} the else break;
}
for (int i=0; i<6; I++) printf (" 0 x % 02 x ", d [I]);
return 0;
}
//0 x12 x34 x12 x78 x56 0 0 0 0 0 x34

CodePudding user response:


Communication protocol should be like this: first text + + data length, data check
For example: AA 44 05 01 02, 03 04 05 & amp; Have spent EA
Here I am assuming that a data, the agreement is as follows:
Data: AA 44
Data length:
Text: 01, 02 03 04 05
Check: EA
Now I have such a TXT file, want to put the data inside the body of parsing out, do you have the code?

CodePudding user response:

I am a rather wild wild reference 3 floor response:
communication protocol should be like this: the first text + + data length, data check
For example: AA 44 05 01 02, 03 04 05 & amp; Have spent EA
Here I am assuming that a data, the agreement is as follows:
Data: AA 44
Data length:
Text: 01, 02 03 04 05
Check: EA
Now I have such a TXT file, want to put the data inside the body of parsing out, do you have the code?


According to the protocol format, define a structure, accordingly, the next is the memcpy,
  • Related