Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Console Application

Console Application

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++data-structuresdebuggingperformance
31 Posts 7 Posters 67 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T toxcct

    edit your message and check the Ignore HTML tags in this message (good for code snippets) so that < and > aren't considered as html tags. :zzz:

    P Offline
    P Offline
    parichaybp
    wrote on last edited by
    #8

    Hi V2, i have sent again hope u get the solution. /// Program to Generate Binary Tree of multiple files and multiple words. #include #include #include #include #include #include #include #include #define MAXWORD 100 struct tnode *addtree(struct tnode *,char *); void treeprint(struct tnode *); #define length (80) struct tnode { char *word; struct tnode *left; struct tnode *right; }; struct tnode *root1 = NULL; struct tnode *talloc(void) { return (struct tnode *) malloc(sizeof(struct tnode)); } char *strdup(char *s) { char *p; p=(char *) malloc(strlen(s)+1); if(p!=NULL) strcpy(p,s); return p; } //addtree add a node with w at or below p struct tnode *addtree(struct tnode *p,char *w) { int cond; if(p==NULL) { p=talloc(); p->word=strdup(w); p->left=p->right=NULL; } else if((cond=strcmp(w,p->word)) == 0) ; else if(cond < 0) p->left=addtree(p->left,w); else p->right=addtree(p->right,w); return p; } // treeprint : in order void treeprint(struct tnode *p) { if(p!=NULL) { treeprint(p->left); printf("%s\n",p->word); treeprint(p->right); } } void ListWords (char *); #define MAX_LEN 100 int main () { char dir[] = "D://Paruichay//"; ListWords(dir); printf("\n\n\t\t Binary Tree :- Each Node Contains 1 word.\n\n"); treeprint(root1); return 0; } /////////Function to list words////// void ListWords (char *dir) { struct _finddata_t file_s; long File_handle; char name[MAX_LEN], words[length]; int j,size; _chdir(dir); if( (File_handle = _findfirst( "*", &file_s )) == -1L ) { printf( "No files in current directory!\n" ); } else if (file_s.attrib & _A_NORMAL) { sprintf (name, "%s",dir); //root = addtree (root, name); //////////////// FILE *fp; fp = fopen(name, "r"); if(fp == NULL) { printf("\n\n Message from _A_NORMAL."); printf("\n\nERROR: could not open file"); exit(EXIT_FAILURE); } else while (fscanf(fp, "%s", &words)!= -1) //while not the end of the file { size = strlen(words); /*determines length of each string */ for(j = 0; j

    C S 2 Replies Last reply
    0
    • P parichaybp

      Hi V2, i have sent again hope u get the solution. /// Program to Generate Binary Tree of multiple files and multiple words. #include #include #include #include #include #include #include #include #define MAXWORD 100 struct tnode *addtree(struct tnode *,char *); void treeprint(struct tnode *); #define length (80) struct tnode { char *word; struct tnode *left; struct tnode *right; }; struct tnode *root1 = NULL; struct tnode *talloc(void) { return (struct tnode *) malloc(sizeof(struct tnode)); } char *strdup(char *s) { char *p; p=(char *) malloc(strlen(s)+1); if(p!=NULL) strcpy(p,s); return p; } //addtree add a node with w at or below p struct tnode *addtree(struct tnode *p,char *w) { int cond; if(p==NULL) { p=talloc(); p->word=strdup(w); p->left=p->right=NULL; } else if((cond=strcmp(w,p->word)) == 0) ; else if(cond < 0) p->left=addtree(p->left,w); else p->right=addtree(p->right,w); return p; } // treeprint : in order void treeprint(struct tnode *p) { if(p!=NULL) { treeprint(p->left); printf("%s\n",p->word); treeprint(p->right); } } void ListWords (char *); #define MAX_LEN 100 int main () { char dir[] = "D://Paruichay//"; ListWords(dir); printf("\n\n\t\t Binary Tree :- Each Node Contains 1 word.\n\n"); treeprint(root1); return 0; } /////////Function to list words////// void ListWords (char *dir) { struct _finddata_t file_s; long File_handle; char name[MAX_LEN], words[length]; int j,size; _chdir(dir); if( (File_handle = _findfirst( "*", &file_s )) == -1L ) { printf( "No files in current directory!\n" ); } else if (file_s.attrib & _A_NORMAL) { sprintf (name, "%s",dir); //root = addtree (root, name); //////////////// FILE *fp; fp = fopen(name, "r"); if(fp == NULL) { printf("\n\n Message from _A_NORMAL."); printf("\n\nERROR: could not open file"); exit(EXIT_FAILURE); } else while (fscanf(fp, "%s", &words)!= -1) //while not the end of the file { size = strlen(words); /*determines length of each string */ for(j = 0; j

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #9

      Did you try to press the cancel button to see where it crashes ? It is VERY helpfull for us to know where (man, I don't want to go through all this code to find the problem)

      P 1 Reply Last reply
      0
      • C Cedric Moonen

        Did you try to press the cancel button to see where it crashes ? It is VERY helpfull for us to know where (man, I don't want to go through all this code to find the problem)

        P Offline
        P Offline
        parichaybp
        wrote on last edited by
        #10

        i get the error message soon after run (Ctrl + F5 ) it does not produce any output

        C 1 Reply Last reply
        0
        • P parichaybp

          i get the error message soon after run (Ctrl + F5 ) it does not produce any output

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #11

          Start your debugger and tell us exactly at which line of code it crashes (press F5 instead of Ctrl + F5). * me :sigh: *

          P 1 Reply Last reply
          0
          • P parichaybp

            Hi , Thanks for the reply. Can u plz check my code and tell me where the error is and why it is getting generated..?// /// Program to Generate Binary Tree of multiple files and multiple words. #include #include #include #include #include #include #include #include #define MAXWORD 100 struct tnode *addtree(struct tnode *,char *); void treeprint(struct tnode *); #define length (80) struct tnode { char *word; struct tnode *left; struct tnode *right; }; struct tnode *root1 = NULL; struct tnode *talloc(void) { return (struct tnode *) malloc(sizeof(struct tnode)); } char *strdup(char *s) { char *p; p=(char *) malloc(strlen(s)+1); if(p!=NULL) strcpy(p,s); return p; } //addtree add a node with w at or below p struct tnode *addtree(struct tnode *p,char *w) { int cond; if(p==NULL) { p=talloc(); p->word=strdup(w); p->left=p->right=NULL; } else if((cond=strcmp(w,p->word)) == 0) ; else if(cond < 0) p->left=addtree(p->left,w); else p->right=addtree(p->right,w); return p; } // treeprint : in order void treeprint(struct tnode *p) { if(p!=NULL) { treeprint(p->left); printf("%s\n",p->word); treeprint(p->right); } } void ListWords (char *); #define MAX_LEN 100 int main () { char dir[] = "D://Parichay/"; ListWords(dir); printf("\n\n\t\t Binary Tree :- Each Node Contains 1 word.\n\n"); treeprint(root1); return 0; } /////////Function to list words////// void ListWords (char *dir) { struct _finddata_t file_s; long File_handle; char name[MAX_LEN], words[length]; int j,size; _chdir(dir); if( (File_handle = _findfirst( "*", &file_s )) == -1L ) { printf( "No files in current directory!\n" ); } else if (file_s.attrib & _A_NORMAL) { sprintf (name, "%s",dir); //root = addtree (root, name); //////////////// FILE *fp; fp = fopen(name, "r"); if(fp == NULL) { printf("\n\n Message from _A_NORMAL."); printf("\n\nERROR: could not open file"); exit(EXIT_FAILURE); } else while (fscanf(fp, "%s", &words)!= -1) //while not the end of the file { size = strlen(words); /*determines length of each string */ for(j = 0; j

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #12

            Does the "crash" occur while adding nodes to the tree, printing the nodes, or scanning the folders? Please try to narrow it down a bit further so that we don't have to examine unnecessary code. You'll get much more help that way.


            "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

            "There is no death, only a change of worlds." - Native American Proverb

            P 1 Reply Last reply
            0
            • C Cedric Moonen

              Start your debugger and tell us exactly at which line of code it crashes (press F5 instead of Ctrl + F5). * me :sigh: *

              P Offline
              P Offline
              parichaybp
              wrote on last edited by
              #13

              hope this will help u. after F5 Loaded 'C:\WINNT\system32\ntdll.dll', no matching symbolic information found. Loaded 'C:\WINNT\system32\KERNEL32.DLL', no matching symbolic information found. First-chance exception in OnlyWords.exe (NTDLL.DLL): 0xC0000005: Access Violation. The thread 0x258 has exited with code -1073741510 (0xC000013A). The program 'D:\Parichay\OnlyWords\Debug\OnlyWords.exe' has exited with code -1073741510 (0xC000013A).

              C 1 Reply Last reply
              0
              • D David Crow

                Does the "crash" occur while adding nodes to the tree, printing the nodes, or scanning the folders? Please try to narrow it down a bit further so that we don't have to examine unnecessary code. You'll get much more help that way.


                "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                "There is no death, only a change of worlds." - Native American Proverb

                P Offline
                P Offline
                parichaybp
                wrote on last edited by
                #14

                program does not produce any output i dnt knwo where it is getting generated.

                C D 2 Replies Last reply
                0
                • P parichaybp

                  hope this will help u. after F5 Loaded 'C:\WINNT\system32\ntdll.dll', no matching symbolic information found. Loaded 'C:\WINNT\system32\KERNEL32.DLL', no matching symbolic information found. First-chance exception in OnlyWords.exe (NTDLL.DLL): 0xC0000005: Access Violation. The thread 0x258 has exited with code -1073741510 (0xC000013A). The program 'D:\Parichay\OnlyWords\Debug\OnlyWords.exe' has exited with code -1073741510 (0xC000013A).

                  C Offline
                  C Offline
                  Cedric Moonen
                  wrote on last edited by
                  #15

                  :omg: :omg: :(( :(( :(( You are kiding aren't you ?? I simply ask you to tell us where the debugger stops when it crashes. At which line of code in your program excactly (there is a yellow arrow next to your code) ? I think your eally need to learn a little bit to work with your debugger. I cannot imagine my life without one ;P. No seriously, try to play a little bit with your debugger to see how to use it. It will be a very good friend that will help you in many many situations.

                  P 1 Reply Last reply
                  0
                  • C Cedric Moonen

                    :omg: :omg: :(( :(( :(( You are kiding aren't you ?? I simply ask you to tell us where the debugger stops when it crashes. At which line of code in your program excactly (there is a yellow arrow next to your code) ? I think your eally need to learn a little bit to work with your debugger. I cannot imagine my life without one ;P. No seriously, try to play a little bit with your debugger to see how to use it. It will be a very good friend that will help you in many many situations.

                    P Offline
                    P Offline
                    parichaybp
                    wrote on last edited by
                    #16

                    77F8910E cmp dword ptr [edx+14h],0 after F5 arrow stopes here .... i have just started learning VC++ so i have very less idea abt Debuggers..

                    C 1 Reply Last reply
                    0
                    • P parichaybp

                      program does not produce any output i dnt knwo where it is getting generated.

                      C Offline
                      C Offline
                      Cedric Moonen
                      wrote on last edited by
                      #17

                      By following what I described in the thread just below. Use your debugger !

                      1 Reply Last reply
                      0
                      • P parichaybp

                        77F8910E cmp dword ptr [edx+14h],0 after F5 arrow stopes here .... i have just started learning VC++ so i have very less idea abt Debuggers..

                        C Offline
                        C Offline
                        Cedric Moonen
                        wrote on last edited by
                        #18

                        Ok, so it is not directly in your code probably. Now, put a breakpoint at the very begining of your program (by going on the line and pressing F9). Then ,put several breakpoints in relevant points in your program. Each time you press F5, the programm will advance to the next bbreakpoint. And there, you can watch to your variables and things like that. Try to play with it and understand how it works, it is really usefull and it will really help you a lot !

                        P M 2 Replies Last reply
                        0
                        • P parichaybp

                          program does not produce any output i dnt knwo where it is getting generated.

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #19

                          But you mentioned a compiler error. What is it? It will be a 4-digit number preceded by a C.


                          "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                          "There is no death, only a change of worlds." - Native American Proverb

                          P 1 Reply Last reply
                          0
                          • C Cedric Moonen

                            Ok, so it is not directly in your code probably. Now, put a breakpoint at the very begining of your program (by going on the line and pressing F9). Then ,put several breakpoints in relevant points in your program. Each time you press F5, the programm will advance to the next bbreakpoint. And there, you can watch to your variables and things like that. Try to play with it and understand how it works, it is really usefull and it will really help you a lot !

                            P Offline
                            P Offline
                            parichaybp
                            wrote on last edited by
                            #20

                            Thanks for the inforamtion. it will help me a lot.... i will try to do that..

                            1 Reply Last reply
                            0
                            • D David Crow

                              But you mentioned a compiler error. What is it? It will be a 4-digit number preceded by a C.


                              "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                              "There is no death, only a change of worlds." - Native American Proverb

                              P Offline
                              P Offline
                              parichaybp
                              wrote on last edited by
                              #21

                              This instruction at "0X77f8910e" referenced memory at "0xc7c7cf0".The memory could not be "read".

                              D 1 Reply Last reply
                              0
                              • C Cedric Moonen

                                Ok, so it is not directly in your code probably. Now, put a breakpoint at the very begining of your program (by going on the line and pressing F9). Then ,put several breakpoints in relevant points in your program. Each time you press F5, the programm will advance to the next bbreakpoint. And there, you can watch to your variables and things like that. Try to play with it and understand how it works, it is really usefull and it will really help you a lot !

                                M Offline
                                M Offline
                                Maxwell Chen
                                wrote on last edited by
                                #22

                                It crashes at here: } while (_findnext (File_handle, &file_s) == 0);


                                Maxwell Chen

                                1 Reply Last reply
                                0
                                • P parichaybp

                                  This instruction at "0X77f8910e" referenced memory at "0xc7c7cf0".The memory could not be "read".

                                  D Offline
                                  D Offline
                                  David Crow
                                  wrote on last edited by
                                  #23

                                  That's a run-time error, not a compilation error. There's a big difference between the two.


                                  "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                                  "There is no death, only a change of worlds." - Native American Proverb

                                  1 Reply Last reply
                                  0
                                  • P parichaybp

                                    Hi , Thanks for the reply. Can u plz check my code and tell me where the error is and why it is getting generated..?// /// Program to Generate Binary Tree of multiple files and multiple words. #include #include #include #include #include #include #include #include #define MAXWORD 100 struct tnode *addtree(struct tnode *,char *); void treeprint(struct tnode *); #define length (80) struct tnode { char *word; struct tnode *left; struct tnode *right; }; struct tnode *root1 = NULL; struct tnode *talloc(void) { return (struct tnode *) malloc(sizeof(struct tnode)); } char *strdup(char *s) { char *p; p=(char *) malloc(strlen(s)+1); if(p!=NULL) strcpy(p,s); return p; } //addtree add a node with w at or below p struct tnode *addtree(struct tnode *p,char *w) { int cond; if(p==NULL) { p=talloc(); p->word=strdup(w); p->left=p->right=NULL; } else if((cond=strcmp(w,p->word)) == 0) ; else if(cond < 0) p->left=addtree(p->left,w); else p->right=addtree(p->right,w); return p; } // treeprint : in order void treeprint(struct tnode *p) { if(p!=NULL) { treeprint(p->left); printf("%s\n",p->word); treeprint(p->right); } } void ListWords (char *); #define MAX_LEN 100 int main () { char dir[] = "D://Parichay/"; ListWords(dir); printf("\n\n\t\t Binary Tree :- Each Node Contains 1 word.\n\n"); treeprint(root1); return 0; } /////////Function to list words////// void ListWords (char *dir) { struct _finddata_t file_s; long File_handle; char name[MAX_LEN], words[length]; int j,size; _chdir(dir); if( (File_handle = _findfirst( "*", &file_s )) == -1L ) { printf( "No files in current directory!\n" ); } else if (file_s.attrib & _A_NORMAL) { sprintf (name, "%s",dir); //root = addtree (root, name); //////////////// FILE *fp; fp = fopen(name, "r"); if(fp == NULL) { printf("\n\n Message from _A_NORMAL."); printf("\n\nERROR: could not open file"); exit(EXIT_FAILURE); } else while (fscanf(fp, "%s", &words)!= -1) //while not the end of the file { size = strlen(words); /*determines length of each string */ for(j = 0; j

                                    D Offline
                                    D Offline
                                    David Crow
                                    wrote on last edited by
                                    #24

                                    parichaybp wrote:

                                    while (fscanf(fp, "%s", &words)!= -1) //while not the end of the file

                                    fscanf() can also return 0, which indicates a potential problem, but the while loop would continue. Is this intentional?


                                    "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                                    "There is no death, only a change of worlds." - Native American Proverb

                                    1 Reply Last reply
                                    0
                                    • P parichaybp

                                      Hi , Thanks for the reply. Can u plz check my code and tell me where the error is and why it is getting generated..?// /// Program to Generate Binary Tree of multiple files and multiple words. #include #include #include #include #include #include #include #include #define MAXWORD 100 struct tnode *addtree(struct tnode *,char *); void treeprint(struct tnode *); #define length (80) struct tnode { char *word; struct tnode *left; struct tnode *right; }; struct tnode *root1 = NULL; struct tnode *talloc(void) { return (struct tnode *) malloc(sizeof(struct tnode)); } char *strdup(char *s) { char *p; p=(char *) malloc(strlen(s)+1); if(p!=NULL) strcpy(p,s); return p; } //addtree add a node with w at or below p struct tnode *addtree(struct tnode *p,char *w) { int cond; if(p==NULL) { p=talloc(); p->word=strdup(w); p->left=p->right=NULL; } else if((cond=strcmp(w,p->word)) == 0) ; else if(cond < 0) p->left=addtree(p->left,w); else p->right=addtree(p->right,w); return p; } // treeprint : in order void treeprint(struct tnode *p) { if(p!=NULL) { treeprint(p->left); printf("%s\n",p->word); treeprint(p->right); } } void ListWords (char *); #define MAX_LEN 100 int main () { char dir[] = "D://Parichay/"; ListWords(dir); printf("\n\n\t\t Binary Tree :- Each Node Contains 1 word.\n\n"); treeprint(root1); return 0; } /////////Function to list words////// void ListWords (char *dir) { struct _finddata_t file_s; long File_handle; char name[MAX_LEN], words[length]; int j,size; _chdir(dir); if( (File_handle = _findfirst( "*", &file_s )) == -1L ) { printf( "No files in current directory!\n" ); } else if (file_s.attrib & _A_NORMAL) { sprintf (name, "%s",dir); //root = addtree (root, name); //////////////// FILE *fp; fp = fopen(name, "r"); if(fp == NULL) { printf("\n\n Message from _A_NORMAL."); printf("\n\nERROR: could not open file"); exit(EXIT_FAILURE); } else while (fscanf(fp, "%s", &words)!= -1) //while not the end of the file { size = strlen(words); /*determines length of each string */ for(j = 0; j

                                      D Offline
                                      D Offline
                                      David Crow
                                      wrote on last edited by
                                      #25

                                      parichaybp wrote:

                                      root1 = addtree (root1, words);

                                      Why do you keep reassigning a new value to root1? That variable should point to the root of the tree no matter what.

                                      parichaybp wrote:

                                      #define MAX_LEN 100

                                      Paths can be longer than 100 characters. Use MAX_PATH instead.


                                      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                                      "There is no death, only a change of worlds." - Native American Proverb

                                      1 Reply Last reply
                                      0
                                      • P parichaybp

                                        Hi , Thanks for the reply. Can u plz check my code and tell me where the error is and why it is getting generated..?// /// Program to Generate Binary Tree of multiple files and multiple words. #include #include #include #include #include #include #include #include #define MAXWORD 100 struct tnode *addtree(struct tnode *,char *); void treeprint(struct tnode *); #define length (80) struct tnode { char *word; struct tnode *left; struct tnode *right; }; struct tnode *root1 = NULL; struct tnode *talloc(void) { return (struct tnode *) malloc(sizeof(struct tnode)); } char *strdup(char *s) { char *p; p=(char *) malloc(strlen(s)+1); if(p!=NULL) strcpy(p,s); return p; } //addtree add a node with w at or below p struct tnode *addtree(struct tnode *p,char *w) { int cond; if(p==NULL) { p=talloc(); p->word=strdup(w); p->left=p->right=NULL; } else if((cond=strcmp(w,p->word)) == 0) ; else if(cond < 0) p->left=addtree(p->left,w); else p->right=addtree(p->right,w); return p; } // treeprint : in order void treeprint(struct tnode *p) { if(p!=NULL) { treeprint(p->left); printf("%s\n",p->word); treeprint(p->right); } } void ListWords (char *); #define MAX_LEN 100 int main () { char dir[] = "D://Parichay/"; ListWords(dir); printf("\n\n\t\t Binary Tree :- Each Node Contains 1 word.\n\n"); treeprint(root1); return 0; } /////////Function to list words////// void ListWords (char *dir) { struct _finddata_t file_s; long File_handle; char name[MAX_LEN], words[length]; int j,size; _chdir(dir); if( (File_handle = _findfirst( "*", &file_s )) == -1L ) { printf( "No files in current directory!\n" ); } else if (file_s.attrib & _A_NORMAL) { sprintf (name, "%s",dir); //root = addtree (root, name); //////////////// FILE *fp; fp = fopen(name, "r"); if(fp == NULL) { printf("\n\n Message from _A_NORMAL."); printf("\n\nERROR: could not open file"); exit(EXIT_FAILURE); } else while (fscanf(fp, "%s", &words)!= -1) //while not the end of the file { size = strlen(words); /*determines length of each string */ for(j = 0; j

                                        D Offline
                                        D Offline
                                        David Crow
                                        wrote on last edited by
                                        #26

                                        parichaybp wrote:

                                        if (strcmp (file_s.name, ".") == 0 || strcmp (file_s.name, "..") == 0)

                                        This can be shortened to just a single comparison:

                                        if (file_s.name[0] == '.')

                                        This does nothing for your problem, but it does help to remove unnecessary code.


                                        "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                                        "There is no death, only a change of worlds." - Native American Proverb

                                        1 Reply Last reply
                                        0
                                        • P parichaybp

                                          Hi , Thanks for the reply. Can u plz check my code and tell me where the error is and why it is getting generated..?// /// Program to Generate Binary Tree of multiple files and multiple words. #include #include #include #include #include #include #include #include #define MAXWORD 100 struct tnode *addtree(struct tnode *,char *); void treeprint(struct tnode *); #define length (80) struct tnode { char *word; struct tnode *left; struct tnode *right; }; struct tnode *root1 = NULL; struct tnode *talloc(void) { return (struct tnode *) malloc(sizeof(struct tnode)); } char *strdup(char *s) { char *p; p=(char *) malloc(strlen(s)+1); if(p!=NULL) strcpy(p,s); return p; } //addtree add a node with w at or below p struct tnode *addtree(struct tnode *p,char *w) { int cond; if(p==NULL) { p=talloc(); p->word=strdup(w); p->left=p->right=NULL; } else if((cond=strcmp(w,p->word)) == 0) ; else if(cond < 0) p->left=addtree(p->left,w); else p->right=addtree(p->right,w); return p; } // treeprint : in order void treeprint(struct tnode *p) { if(p!=NULL) { treeprint(p->left); printf("%s\n",p->word); treeprint(p->right); } } void ListWords (char *); #define MAX_LEN 100 int main () { char dir[] = "D://Parichay/"; ListWords(dir); printf("\n\n\t\t Binary Tree :- Each Node Contains 1 word.\n\n"); treeprint(root1); return 0; } /////////Function to list words////// void ListWords (char *dir) { struct _finddata_t file_s; long File_handle; char name[MAX_LEN], words[length]; int j,size; _chdir(dir); if( (File_handle = _findfirst( "*", &file_s )) == -1L ) { printf( "No files in current directory!\n" ); } else if (file_s.attrib & _A_NORMAL) { sprintf (name, "%s",dir); //root = addtree (root, name); //////////////// FILE *fp; fp = fopen(name, "r"); if(fp == NULL) { printf("\n\n Message from _A_NORMAL."); printf("\n\nERROR: could not open file"); exit(EXIT_FAILURE); } else while (fscanf(fp, "%s", &words)!= -1) //while not the end of the file { size = strlen(words); /*determines length of each string */ for(j = 0; j

                                          D Offline
                                          D Offline
                                          David Crow
                                          wrote on last edited by
                                          #27

                                          Have you tried just navigating through the files/folders without adding anything to the tree data structure?


                                          "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                                          "There is no death, only a change of worlds." - Native American Proverb

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups