473,513 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to print File pointer

2 New Member
Hi

I have a file pointer which is pointing to a file in the physical disk. Now I wanted to know which file it is pointing to. Is there a way to print it using file pointer.

Regards
Padma
Sep 11 '07 #1
3 24457
RRick
463 Recognized Expert Contributor
The simplest way is to get the program in the debugger and look at the file pointer.

GNU will let you see the values, but I doubt it will help you. For the following program
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int main( void)
  4. {
  5.     FILE * file = fopen( "t.c", "r");
  6.  
  7.     printf ( "FILE: %p\n", file);
  8. }
When stopped at line 7, the debugger says:
Expand|Select|Wrap|Line Numbers
  1. (gdb) p *file
  2. $3 = {
  3.   _flags = -72539000, 
  4.   _IO_read_ptr = 0x0, 
  5.   _IO_read_end = 0x0, 
  6.   _IO_read_base = 0x0, 
  7.   _IO_write_base = 0x0, 
  8.   _IO_write_ptr = 0x0, 
  9.   _IO_write_end = 0x0, 
  10.   _IO_buf_base = 0x0, 
  11.   _IO_buf_end = 0x0, 
  12.   _IO_save_base = 0x0, 
  13.   _IO_backup_base = 0x0, 
  14.   _IO_save_end = 0x0, 
  15.   _markers = 0x0, 
  16.   _chain = 0x70d480, 
  17.   _fileno = 7, 
  18.   _flags2 = 0, 
  19.   _old_offset = 0, 
  20.   _cur_column = 0, 
  21.   _vtable_offset = 0 '\0', 
  22.   _shortbuf =     "", 
  23.   _lock = 0x8ae40a0, 
  24.   _offset = -1, 
  25.   __pad1 = 0x0, 
  26.   __pad2 = 0x8ae40ac, 
  27.   _mode = 0, 
  28.   _unused2 =     '\0' <repeats 51 times>
  29. }
  30.  
I don't see a lot of useful information here.
Sep 12 '07 #2
Banfa
9,065 Recognized Expert Moderator Expert
I have a file pointer which is pointing to a file in the physical disk. Now I wanted to know which file it is pointing to. Is there a way to print it using file pointer.
Yes store the name of the file that you opened when you open it.
Sep 12 '07 #3
Banfa
9,065 Recognized Expert Moderator Expert
I don't see a lot of useful information here.
Not to mention that that information would be platform dependent and not guaranteed to be the same on all systems (although it probably would be the same on all systems running the same OS on the same hardware).
Sep 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

30
4129
by: Martin Bless | last post by:
Why can't we have an additional 'print' statement, that behaves exactly like 'print' but doesn't insert that damn blank between two arguments? Could be called 'printn' or 'prin1' or 'prinn' anything similar you like. Would make my life so much easier. Often I start with a nice and short print statement, then there happen to be more...
0
3911
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header,...
2
1921
by: Ed Bitzer | last post by:
I can locate tab stops in a RichTextBox but have not found a way to maintain that positioning when I print. At the Knowledge Discovery Keys Site (http://www.kdkeys.net/forums/3122/ShowPost.aspx) Baily explains that character printing isn't really supported in VB .Net, the TAB method does not apply. The DrawString method is used to send...
12
2417
by: Peter Lin | last post by:
Hey, I am just wondering if anyone has got any idea of setting up a new class so that you could just print like the old ways with the printer class, since I am writing a program that really requires simple black and white text printing, but there is alot to print and it's needed at various places, which is why I find that the new printing...
2
22837
by: Bill_DBA | last post by:
I have the following stored procedure that is called from the source of a transformation in a DTS package. The first parameter turns on PRINT debug messages. The second, when equals 1, turns on the openning, fetching, and closing of a cursor. Things are fine if only one of the two parameters was set to 1. When run with both parameters...
8
11361
by: sam_cit | last post by:
Hi, I hear many say that it is better to convert address, i mean, type cast into (void*) and print using %p identifier rather than %u, could you let me know the specific reason behind it?
6
35659
by: scoobydoo666 | last post by:
Hi Could any one tell me how to print size of char pointer array? for example char *ptrArray=new; cout<<sizeof(ptrArray); The above code will print 4 (pointer size) instead of 25. how do I print 25? Thanks in advance
1
4261
by: zackp | last post by:
Hello, I am learning C++ lately. This morning, out of curiosity I constructed a simple code below, but to my surprise, when char* is used, the program fails to print almost anything. The only thing I got is the following: % : np = As soon as I use a pointer to another type, everything behaves as
21
2880
by: arnuld | last post by:
I have created a program to print the input words on stdout. Input is taken dynamically from stdin. In each word, each input character is allocated dynamically. I have ran this program with a file containing a *single* word made of 25525500 letters and this program works fine on it. I will welcome any suggestions for improvement. /* * A...
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7128
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5704
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4759
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3242
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.