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.