Hello!

I have what I want to print to file current printf-ing on my console. Can I have some help getting it to do the same, only this time to file please. I can't get it to work.

Many thanks

for(i= 0; i <= k; i++)
    {
    add = (unsigned char *)s; 
    data = *add; 
    printf("data = %02x \n\r",data);
    s++;
    }

Recommended Answers

All 4 Replies

Open a file stream using fopen(), then call fprintf() instead of printf(). Alternatively, you could redirect stdin into a file, but I don't get the impression that this is what you want.

awesome - just what i need!

What deceptikon said, except instead of "redirect stdin", it should read "redirect stdout"... :-) Another case of the keyboard mis-interpreting the user's intent... :-)

except instead of "redirect stdin", it should read "redirect stdout"... :-)

I have an excuse for that brain fart this time. I spent a large portion of the afternoon working on the input half of a standard C library implementation, so I had stdin on the brain. Give it a few days and I'll type stdout when I mean stdin. ;)

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.