从C文件指针获取文件名 [英] Obtain filename from file pointer in C

查看:183
本文介绍了从C文件指针获取文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  获取文件名从文件描述符使用C 结果
  其如何获取文件名FILE *?

有什么办法,我可以找到从文件指针在C FILE_NAME?

Is there any way where I can find the file_name from a file-pointer in C?

fp = fopen(file,"r");

这是FP,是有可能得到,我已经打开了文件名?

From fp, is it possible to get the file name which I have opened?

推荐答案

我不信,因为文件*可能的东西,甚至没有一个名字。有可能是一个依赖于平台的方式,这取决于一,您的系统,所以如果你不关心可移植性,尝试寻找文件的编译器的定义,如果它有一个。赔率是你唯一的办法就是它打开时保存名称。

I believe not, because a file* could be to something that doesn't even have a name. There might be a platform dependent way, depending I. Your system, so if you don't care about portability, try looking at your compiler's definition of FILE if it has one. Odds are that your only way is to save the name when it's opened.

有一些其他的潜在哈克的方式作为良好检查此链接:

There are some other potentially hacky ways as well- check this link:

http://bytes.com/topic/ C /答案/ 218921-如何,获得文件名,文件指针

干杯!

这篇关于从C文件指针获取文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆