Click here to Skip to main content
13,143,774 members (31,801 online)
Rate this:
 
Please Sign up or sign in to vote.
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <dir.h>
#include <string.h>
#include <alloc.h>
#include <stdlib.h>
 
struct btreenode
{
    struct btreenode *leftchild ;
    char data[13] ; /* file name */
    char *loc ; /* location of filename */
    struct btreenode *rightchild ;
} *bt = NULL ;
 
void disktree( ) ;
int insert ( struct btreenode  **, char*, char* ) ;
 
void main( )
{
    char current_dir[32] ;
 
    clrscr( ) ;
 
    getcwd ( current_dir, 32 ) ;
    chdir ( "\\" ) ;
    disktree( ) ;
    chdir ( current_dir ) ;
 
    getch( ) ;
}
 
void disktree( )
{
    struct ffblk file ;
    int flag ;
    char loc[80] ;
 
    getcwd ( loc, 80 ) ;
    flag =  findfirst ( "*.*", &file, FA_NORMAL | FA_RDONLY | FA_HIDDEN |
		    FA_SYSTEM | FA_LABEL | FA_DIREC | FA_ARCH ) ;
 
    while ( flag == 0 )
    {
	if ( file.ff_name[0] != '.' )
	{
	    if ( file.ff_attrib == FA_DIREC && file.ff_fsize == 0 )
	    {
		chdir ( file.ff_name ) ;
		disktree( ) ;
		chdir ( loc ) ;
	    }
	    else
		insert ( &bt, loc, file.ff_name ) ;
	}
	flag = findnext ( &file ) ;
    }
}
 
/* inserts a new node in a binary search tree */
int insert ( struct btreenode  **sr, char* l, char* f )
{
    char *p ;
    int flag ;
 
    if ( *sr == NULL )
    {
	*sr = ( struct btreenode * ) malloc ( sizeof ( struct btreenode ) ) ;
 
	if ( *sr == NULL )
	{
	    printf ( "\nOut of memory." ) ;
	    exit(1);
	}
 
	( *sr ) -> leftchild = NULL ;
	( *sr ) -> rightchild = NULL ;
	strcpy ( ( *sr ) -> data, f ) ;
	p = ( char * ) malloc ( ( strlen ( l ) + 1 ) ) ;
 
	if ( p == NULL )
	{
	    printf ( "\nOut of memory." ) ;
	    exit(1);
	}
 
	strcpy ( p, l ) ;
	( *sr ) -> loc = p ;
    }
    else
    {
	flag = strcmp ( ( *sr ) -> data, f ) ;
 
	if ( flag == 0 )
	{
	    printf ( "org: %s", ( *sr ) -> loc ) ;
 
	    if ( strlen ( ( *sr ) -> loc ) > 4 )
	    {
		printf ( "\\" ) ;
		printf ( "%s\n", ( *sr ) -> data ) ;
		printf ("dup: %s", l ) ;
	    }
	    if ( strlen ( l ) > 4 )
	    {
		printf ( "\\" ) ;
		printf ( "%s\n\n", f ) ;
	    }
	}
	else if (flag < 0 )
        {
	    insert ( &( ( *sr ) -> leftchild ), l, f ) ;
        }
	else
	    insert ( &( ( *sr ) -> rightchild ), l, f ) ;
    }
    return 0;
}
Posted 1-Nov-14 19:32pm
Updated 1-Nov-14 19:46pm
v2
Comments
George Jonsson 2-Nov-14 1:49am
   
Removed the urgency. It is only urgent to you and unless you want to pay for the help, it is not urgent for anyone else.
Also try to format the code if you want anyone to bother to read it through.
(I did it for you this time)

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

How long are filenames? from your code:
<br />
  char data[13] ; /* file name */<br />
  char current_dir[32] ;<br />
  char loc[80] ; <br />

Also, if you have two conditions around any output. Are they correct?
if ( strlen ( ( *sr ) -> loc ) > 4 )<br />
if ( strlen ( l ) > 4 )<br />
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 3 Nov 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100