I'm having a problem writing an unsigned char array to a file.

When I write it to stdout using printf, it displays properly, however if I write it to a file, when I open it, I can't read the file. It looks like it may be writing the file in binary(?).

Here is the code I'm using:

for(int k = 0; k < bits; k++)
    myfile << bitArray[k];
myfile << "\n";  // Adds new line after the array is printed

Any ideas?


Post your full code. If it's too long, pare it down into something complete, but with all of the relevant parts. Trying to troubleshoot with tiny snippets is frustrating.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.