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?

Thanks.

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.