Is it possible to retrieve a file’s name in C? If a file is created like the following:
FILE *f = fopen ("foo.txt", "r");
And the “foo.txt” comes from a variable out of scope. Is there a way to retrieve it from the FILE struct?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t in fact retrieve the file names from your
FILEobjects.However, if the name being passed to
fopenis important to you, and that variable is out of scope for whatever reason, you could always wrap aFILE*in a struct, ie.At least that’s what I’d do but it depends on what you’re actually trying to do.