Sign in to follow this  
soconne

how to get errors associated with studio.h functions

Recommended Posts

soconne    105
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
aidan_walsh    739
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
Kalazart    148
'/' 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
soconne    105
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
SiCrane    11839
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this