Fix trailing slashes which leads to segfault.
Add extra check to opened file opointer.
Merge pull request #55 from aitjcize/fix-path-name

Fix trailing slashes which leads to segfault.