Hi yazu,
Many thanks for your code.
After I read through and try to understand the logic of your code.
I'm find the following doubts that need your advice:
1. Can I know why you will set "char * pinp = inp+1; char * pref = ref+1;" ?
2. Sad to said that I can't really get the meaning of "rewind(finp);" in the code

This is the first time I deal with "rewind" function.
Many thanks for your advice.