Added header <sys/stat.h>, changed sprintf for strndup and fixed Segmentation Fault on example