in reply to Get filename inside each file

Not very helpful, but I have to say it: Perl originally was created to solve this kind of problems. Don't even think of writing a (throwaway) C program for it, especially if you're new to C.