what could cause seg fault in this code?

I'm designing a program for appending a few lines at certain line from a file.
the procedure is read from a file & store the lines into a link list, append at certain line then write it to result.txt.
However, my firstline is not working properly.