Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

getting the file's name?

I am trying to get the file's name in this this way.

void do_more( FILE *fp)
{
        printf(fp);
...
}
Is this possible to do or i have to find a different way?
Thanks
0
Carl3003
Asked:
Carl3003
2 Solutions
 
efnCommented:
You have to find a different way.  Normally, you keep track of the name as a character string separate from the FILE pointer.
0
 
sunnycoderCommented:
Hi Carl3003,

You would have specified the file name somewhere when you obtained the FILE * fp. You will have to use that. There is no ANSI C function which will give you the file name when you supply the FILE *.

There are some other platform specific solutions such as examining ls -l /proc/<pid>/fd on various flavours of linux. However, I will still recommend using the information yuo already have rather than fish for it in an unportable way.

cheers
sunnycoder
0
 
Carl3003Author Commented:
yes, i past the char array and then print the file name..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now