Thread: Recursion

  1. #1
    Unregistered
    Guest

    Recursion

    Wanna know if this is a good Recursive function

    Code:
    int Recurse(char *argv)													//recursion is a joy
    {
       FILEINFO				FileName;										//remember I defined _finddata_t as FILEINFO up at the top
       long					lFileHandle = 0;
       int					nDone = 0;
       long					nNumFiles = 0;
       int					nCount = 0;
       char					FilePathBuffer[256];
       char					WildCard[] = "\\*.*";
       const char				IdxWildCard[] = "*.IDX";
       char					FileNameBuffer[101][10] = {0};
       bool					bCheckedDir = false;
    
       while(argv[nCount] != '*')												//find '*' and omit it
       {
    	   FilePathBuffer[nCount] = argv[nCount];								//copy to FilePathBuffer so I have an uncorrupted copy for the filepath
    	   nCount++;														//count for later use with catenation
       }
       FilePathBuffer[nCount] = '\0';											//cantenate
    
    
       lFileHandle = _findfirst(argv, &FileName);								//retrieve first file and a handle to the files
       while(!lFileHandle || !nDone)
       {
    	   nNumFiles++;
    	   if(FileName.name[0] != '.')
    	   {
    		   nNumFilesTotal++;
    	   }
    
    	   if(!bCheckedDir)
    	   {
    		   strncat(FilePathBuffer, IdxWildCard, 10);
    		   GetFileNames(FilePathBuffer, FileNameBuffer);
    		   GetPathName(FilePathBuffer, FileNameBuffer);
    		   FilePathBuffer[nCount] = '\0';
    		   bCheckedDir = true;
    	   }
    
    	   if((FileName.attrib == 16 || FileName.attrib == 17 || FileName.attrib == 18 || FileName.attrib == 2066) && FileName.name[0] != '.')
    	   {
    		   strncat(FilePathBuffer, FileName.name, strlen(FileName.name));
    		   strncat(FilePathBuffer, WildCard, strlen(WildCard));
    		   Recurse(FilePathBuffer);
    		   FilePathBuffer[nCount] = '\0';
    	   }
    
    	   nDone = _findnext(lFileHandle, &FileName);
       }
       return 0;
    }

  2. #2
    Registered User raimo's Avatar
    Join Date
    Jun 2002
    Posts
    107
    Wanna know if this is a good Recursive function
    Do you want me to answer yes or no? What is the problem?

  3. #3
    Unregistered
    Guest
    just kinda wondering what changes you guys would make to it

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    For starters i'd change the name of the function!

    'Recurse' is a useless name.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Is there really a such thing as a good recursive function

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    Now THAT's a good question

    Well, yeah there is, as long as you dont care about performance!

    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  7. #7
    Unregistered
    Guest
    Ok change the name to CheckDir

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, 02:58 AM
  3. Recursion... why?
    By swgh in forum C++ Programming
    Replies: 4
    Last Post: 06-09-2008, 09:37 AM
  4. a simple recursion question
    By tetra in forum C++ Programming
    Replies: 6
    Last Post: 10-27-2002, 10:56 AM
  5. To Recur(sion) or to Iterate?That is the question
    By jasrajva in forum C Programming
    Replies: 4
    Last Post: 11-07-2001, 09:24 AM