linux - Write hexadecimal to file in C (not ASCII) -


I am trying to convert some binary string to hexadecimal values ​​and write it directly in the file. I mean the value should be visible only by the hex editor and I do not care about the ASCII text in the file.

Here is a part of my code:

  unsigned int value; Four p [4]; File * FP; Fp = fopen ("file.txt", "wb +"); // sprintoff (p, "\\ x% x", hex); Value = stratol ("10010011", tap, 2); Philit (& amp; Mann, Stellen (P), 1, FP); // fright (p, stellon (p), 1, fp);   

I try to use the filler to write the file, it starts working, but it will write 4 bytes instead of 1 byte hex (00 to padding) I " Tried to print the string starting with "x" and tried to write the file string (comment this piece of code), but it will write to write "\ x" to write in the ASCII format which is not me needed. Does anyone know how to do this or what is wrong with my code? Thank you. Do not use

strlen , because gives length

which is 8 in this case, so it writes 8 bytes. Instead of using sizeof , you are using a int data type, whose size can vary depending on your platform if you simply If you want to write byte, then use an unsigned char, your code will be:
  Unsigned four values; Four p [4]; File * FP; Fp = fopen ("file.txt", "wb +"); Value = stratol ("10010011", tap, 2); Fwrite (& amp; value, sizeof (value), 1, fp); // fright (p, stellon (p), 1, fp);   

Does this answer your question?

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -