get name of FILE* in c

Oct 18, 2013 at 2:45am
closed account (Dy7SLyTq)
so i have an array of files stored in a FILE* and need to check if they exist. if they dont, i want to print an error, but i dont know how to get the name which i want for the error message
Oct 18, 2013 at 4:18am
Which name? Do you mean the format of the error message?
Last edited on Oct 18, 2013 at 4:19am
Oct 18, 2013 at 4:31am
closed account (Dy7SLyTq)
the name of the file which FILE* interfaces with
Oct 18, 2013 at 4:52am
Why are you using C FILE * when you could be using C++ file streams or, better yet, Boost?
Oct 18, 2013 at 5:26am
A FILE* doesn't necessarily map to a file (example: stdout) and therefore may not have a "name". So I'm pretty sure there's no way to get the filename from a FILE*.
Oct 18, 2013 at 6:13am
There's ways to get it in windows and linux according to these answers http://stackoverflow.com/questions/4305355/how-get-filename-having-file
I don't think there's a portable way of doing this.
Oct 18, 2013 at 5:30pm
closed account (Dy7SLyTq)
Why are you using C FILE * when you could be using C++ file streams or, better yet, Boost?

im doing it in c/assembly. its good learning. there was a lot that i took for granted and didnt realize (like function overloading)

A FILE* doesn't necessarily map to a file (example: stdout) and therefore may not have a "name". So I'm pretty sure there's no way to get the filename from a FILE*.
good to know thanks.

@lachlan thanks ill take a look
Topic archived. No new replies allowed.