I'm actually trying to fprintf an unsigned char array in its hexadecimal representation in a file.
To do that, I use this code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
unsigned char tab[...] = "...";
FILE* Output = NULL;
Output = fopen("Output.txt", "w+");
tabLength = sizeof(tab);
for ( unsigned int i = 0; i < tabLength; i++ )
fprintf(Output, "%2X", tab[i]);
fclose(Output);
}
With a small array, no problem, but as it tends towards big arrays (200M element in my case), it gets a lot longer :(
If some of you have an option to do the job in a faster way, I would be glad :)
EDIT:
tabLength = strlen(tab) --> tabLength = sizeof(tab);
2*tabLength.sprintfall your hexs into it. Write it into the file with one singlefwrite.tabin several parts which ones Isprintfin the second array tofwriteit, will my method be efficient or will it lose its interest ? Also, willfwritewrite the hexa in plaintext like "2E" because i want it to do so.printfs. Merge as many as you can afford.fwritewill honestly copy the content of the buffer to the disk.