Recursion help needed

This is a discussion on Recursion help needed within the C Programming forums, part of the General Programming Boards category; Hi, First off I am a complete novice at c programming. I have been trying to modify to this piece ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    9

    Recursion help needed

    Hi,

    First off I am a complete novice at c programming. I have been trying to modify to this piece of code to add recursion and use opendir and readdir instead of scandir:

    Code:
     removed
    Code:
    removed
    The 2 pieces of code are from 2 different programs which do the same thing. So basically I am trying to merge the top piece of code into the same type of format of the second piece, but I
    am stuck on how to do this.

    Any help would be greatly appreciated.
    Last edited by lewiso; 03-03-2008 at 05:05 AM.

  2. #2
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    In order to make it recursive, there has to be a function somewhere but i don't see the function head.
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    9
    Thanks for your reply


    Ok. As I mentioned I am a complete novice, so I'll paste the full programs in.


    This is the program I have written (poorly):

    Code:
    removed
    This is the one I would prefer to use but there is no recursion. Also I am required to use at least the following system calls, opendir, chdir, readdir, and stat.:

    Code:
    removed
    How can I modify the second one to make it recursive and using the required system calls?
    Last edited by lewiso; 03-03-2008 at 05:04 AM.

  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,652
    Same person as here?

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    9
    Nope thats not me

  6. #6
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    Consider using attachments for so big files of code. It would make it easier for most people to study it. I believe that you must isolate from the code, the part that does the recursive descent in the directory structure. Also how would the printing take place is important. Consider reading this: Tree traversal.
    I would probably do it like:
    Code:
    Pseudocode:
    SUB print_dir(String rootDir)
    BEGIN
        STATISTICS(rootDir)
        IF (isDirectory(rootDir))
        BEGIN
            files = readFilesOf(rootDir);
            FOREACH file IN files DO
            BEGIN
                print_dir(file)
            END
        END
    END
    However that method might not yield the results you would like.
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  7. #7
    Registered User
    Join Date
    Mar 2008
    Posts
    9
    Thanks for the reply, but that does not make much sense to me (not much to do with this does).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Template Recursion Pickle
    By SevenThunders in forum C++ Programming
    Replies: 20
    Last Post: 02-05-2009, 09:45 PM
  2. convert Recursion to linear can it be done
    By umen242 in forum C++ Programming
    Replies: 2
    Last Post: 10-15-2008, 03:58 AM
  3. a simple recursion question
    By tetra in forum C++ Programming
    Replies: 6
    Last Post: 10-27-2002, 10:56 AM
  4. stack and recursion help needed!
    By LouB in forum C++ Programming
    Replies: 3
    Last Post: 07-01-2002, 03:19 PM
  5. selection sorting using going-down and going-up recursion
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-02-2001, 02:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21