Basic and Advance C Question:

Download Job Interview Questions and Answers PDF

How can I recover the file name given an open stream?

C Programming Interview Question
C Programming Interview Question

Answer:

This problem is, in general, insoluble. Under Unix, for instance, a scan of the entire disk (perhaps involving special permissions) would theoretically be required, and would fail if the descriptor were connected to a pipe or referred to a deleted file (and could give a misleading answer for a file with multiple links). It is best to remember the names of files yourself as you open them (perhaps with a wrapper function around fopen).

Download C Programming Interview Questions And Answers PDF

Previous QuestionNext Question
Once I have used freopen, how can I get the original stdout (or stdin) back?How can I insert or delete a line (or record) in the middle of a file?