There is one mistake here:
while (fgetc(ptr) != EOF)
doesn't just work as a condition, but it does read a char
and moves on, so next time you read a string
it's gonna miss the first char
of the word because it was read by fgetc()
. Fix that and report back. I would suggest you use the fscanf()
in your loop condition instead (but then remove it from inside the body of the loop).