LinuxQuestions.org has an attachment system. Please attach your file by clicking the "Manage Attachments" button under "Additional Options" when you post.
NOTE: You may have to rename your file with a ".txt" extension.
As to your question, check the man page for each system call. Each call usually returns a specific value (e.g., -1) when an error occurs, and sets a variable "errno" to a value which indicates the nature of the error. You should include the header errno.h (by writing "#include <errno.h>" on its own line near the top of the file), and use its functions to access errno. For example, if an error occurs, you can use
to print out a description of the error.
Finally, a little LQ etiquette: if someone helps you, click the scales icon on their post, and when your question is answered, click "Thread tools -> Mark thread as solved"