Solved

getting the file's name?

Posted on 2004-09-19
3
173 Views
Last Modified: 2010-04-15
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
Comment
Question by:Carl3003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Accepted Solution

by:
efn earned 25 total points
ID: 12099286
You have to find a different way.  Normally, you keep track of the name as a character string separate from the FILE pointer.
0
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 25 total points
ID: 12099392
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
 

Author Comment

by:Carl3003
ID: 12102847
yes, i past the char array and then print the file name..
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question