Sign in to follow this  

how to get errors associated with studio.h functions

This topic is 4329 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having a problem with fopen not opening files that actually exist on the hard drive. So I'm trying to figure out how to get the associated error. I tried using perror("c:/output.txt") but it doesn't create the file with the errors. How can I capture the output or at least redirect stderr to a file?

Share this post


Link to post
Share on other sites
Since "\" can be used as a special character in C-style languages, you have to use the escape character "\\" instead. This should work the same for "/", I think.

Share this post


Link to post
Share on other sites
'/' is just '/'. As you said, \ is the escape sequence onde, so it needs \\ to show you wanna print \, not the sequence.

You want to be able to differ from can't open existing file error and there is no file to open error? Because using "w" or "a" modes (with modifiers also) will created a new file, if there isn't one with that name.

Share this post


Link to post
Share on other sites
Okay, but the real question is how to direct the errors of the standard library to a file. Do you just use perror or is there some other method?

Share this post


Link to post
Share on other sites
To direct stderr to a file you can use shell redirection. For example, when running your program with sh based shells you can use pp 2> file to direct stderr to the file file. Programmatically you can use freopen() to direct stderr to a file within your program.

Share this post


Link to post
Share on other sites
Sign in to follow this