Home > Back-end >  Cooking chicken to ask: statistics the number of binary file an ASCII. It's really difficult to
Cooking chicken to ask: statistics the number of binary file an ASCII. It's really difficult to

Time:09-17

Input a hexadecimal number two, statistics, how many bytes of the binary file a. d. at its value equals the hexadecimal number, the results must be written in the "% d \ n" format to the text file b.t xt, for example: set a. d. ats contains the following content (has been converted to hexadecimal format shows) :
:
0 x01 0 x02 0 x03 0 x41 x0d x43 x42 0 0 0 0 x0a
0 XFF 0 xfe XFD 0 0 x01 0 x02 0 x03 0 x80 0 x7f
0 x0d 0 x0a
Input and output sample:

Input:
01
Output:
2
Because the file has 2 0 x01,

Input:
FF
Output:
1
Because the file have 1 0 XFF,
This how to do??????

CodePudding user response:

Read the file, and then compare

CodePudding user response:

The
Quote: reference 1/f, Simple, Soft reply:

Read the file, then compared [/quote can have specific code? Is I do not understand the process of (here is my code)
#include
#include
The main ()
{
Long len.
The FILE * fp1, * fp2;
Int count=0, a, I;
Char * buf.
Fp1=fopen (a. d. "at" and "rb");
Fp2=fopen (b.t xt ""," w ");
The scanf (" % p ", & amp; A);
Fseek (fp1, 0, SEEK_END);
Len=ftell (fp1);
The rewind (fp1);
Buf=malloc (len);
for(i=0; iFread (& amp; Buf [I], 1, 1, fp1);
for(i=0; i{
If (buf (I)==a)
count++;
}
Fprintf (fp2, "% d", count);
The fclose (fp1);
The fclose (fp2);
}
  • Related