dose any one know how exactly to do recursion in C. i am trying to simply make a program to list files in a directory and recursivly goes through each sub directory and list the files they contain. i cant seem to get it to go more than one levle deep, because once i am down one level my check to see if the file i have encountered is a directory always returns 0. i am using the macro in the sys/stat.h and unistd.h libraries which is S_ISDIR(statBuffer.st_mode);
any help on this topic would be great
Rcursion in C???
You need to think about your exit return.
function yourfunction(isfinished)
{
if (isfinished==false)
{
do something if it's done isfinished=true
yourfunction(isfinished);
}
}
public void main()
{
bool isfinished='false';
yourfunction(isfinished);
}
Something like that.
Reply:Since your problem is that your function which checks if the element of a directory is itself ALSO a directory (You said it always returns a 0) Then I guess all you have to do is fixed that function and ensure that it recognizes a directory file from the other files in this way you can know when to go deeper (If you found out that the file is also a directory itself)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment