Click here to Skip to main content
15,881,733 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
I was asked this question in an interview. How to implement the equivalent of Unix command tail -f in C or C++. Can someone please advise.

I think we should use ftell, fseek, but not quite sure though.

Thanks,
Ganesh
Posted
Updated 2-Jun-10 12:07pm
v2

why not just read tail's source code or try to implement it? :)
 
Share this answer
 
I would use the getline function and recursion.
 
Share this answer
 
Comments
CPallini 2-Jun-10 15:50pm    
Why recursion?
Moak 2-Jun-10 18:05pm    
Why no threads?
«_Superman_» 3-Jun-10 1:09am    
Long term memory loss. :o)
Moak 3-Jun-10 4:31am    
Grin :)
I think the file change notification is the key when asked a question like that. Not how you read a file, because everyone knows how to read a file.

FindFirstChangeNotification() would work on windows followed by a WaitForXxxObject()to avoid having a timer.

Knowing the names of the functions is probably not necessary at an interview, but knowing about them and describing the technique is more valuable.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900