Problem in system call

Dear Friends,
I write a c program to list the directories recursively. For this I write a function called my_readdir to read the content of directory. For this I use read system call it returns -1, then I use readdir system call it gives comment terminated error or segmentation fault. How i correct that program.

How to use readdir system call

you have to handle directories this way,

opendir
readdir
closedir