Solved

Can you get the filename of a file opened with fopen?

Posted on 2004-08-09
4
196 Views
Last Modified: 2010-04-15
Hi.  Is it possible to get the filename of a file that has been opened with fopen?  In other words, I have a global FILE pointer.  It gets opened in main().  Later, I want to be able to get the filename associated with it.  Can I use the file pointer to get it, or do I need to save the filename in memory?

Thanks.
0
Comment
Question by:mromeo
[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
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
keteracel earned 100 total points
ID: 11753465
unfortunately not.... I've hacked the include files on linux and the filename is not included anywhere. Why can't you just globally store the filename when you globally store the file?
0
 

Author Comment

by:mromeo
ID: 11753575
I can, but didn't want to do that if it wasn't necessary. The program is hefty to begin with and keeping memory allocation to a minimum is desirable.  Thanks for your info.
0
 
LVL 9

Expert Comment

by:keteracel
ID: 11753771
do you actually need the filename anyway?
0
 

Author Comment

by:mromeo
ID: 11753805
I'm trying to remove the TOP portion of the file.  So I'm reading the bottom portion of the file, saving it to a buffer, removing the original file (with unlink -- which is where the filename comes in) and writing the buffer out to a new file with the same file name.  Can you think of a more efficient way of doing it?
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

Suggested Solutions

Title # Comments Views Activity
Passing a array as parameter - C 2 110
Detect CR LF to each line 12 185
How to pass pointer to int when expected type is pointer to const char *   ? 6 74
Windows 10 14 36
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

732 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