Click here to Skip to main content
15,911,786 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: COMMAND LINE ARGUMENT Pin
jai_sendme14-Apr-06 4:49
jai_sendme14-Apr-06 4:49 
QuestionRe: COMMAND LINE ARGUMENT Pin
David Crow14-Apr-06 5:21
David Crow14-Apr-06 5:21 
Questionchild windows are not being updated + mdi Pin
Veeresh Hiremath14-Apr-06 1:54
Veeresh Hiremath14-Apr-06 1:54 
AnswerRe: child windows are not being updated + mdi Pin
Russell'14-Apr-06 3:13
Russell'14-Apr-06 3:13 
GeneralRe: child windows are not being updated + mdi Pin
Veeresh Hiremath14-Apr-06 4:22
Veeresh Hiremath14-Apr-06 4:22 
QuestionConsole Application Pin
parichaybp14-Apr-06 1:31
parichaybp14-Apr-06 1:31 
AnswerRe: Console Application Pin
Maxwell Chen14-Apr-06 1:48
Maxwell Chen14-Apr-06 1:48 
GeneralRe: Console Application Pin
parichaybp14-Apr-06 1:51
parichaybp14-Apr-06 1:51 
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 <iostream.h>
#include <stdio.h>
#include <assert.h>
#include <io.h>
#include <direct.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>


#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<size; j++)="" *begins="" iteration="" of="" each="" string="" looking="" for="" non-alpha="" characters="" then="" it="" lower="" cases="" all="" *=""
="" {
="" if="" (words[j]="='.'" ||="" words[j]="=','" j++;="" *removes="" non="" alpha-characters="" strlwr(words);="" printf("%c",="" words[j]);="" *prints="" to="" screen="" words=""

="" root1="addtree" (root1,="" words);
="" }
="" fclose(fp);

="" }="" else="" do="" (strcmp="" (file_s.name,="" ".")="=" 0="" strcmp="" "..")="=" 0)
="" continue;
="" (strlen="" (dir)="" +="" strlen="" (file_s.name)="" 2=""> sizeof (name))
{
fprintf (stderr, "Dir name too long\n");
return;
}

if (file_s.attrib & _A_SUBDIR)
{
sprintf (name, "%s/%s",dir, file_s.name);
ListWords(name);
}
else
{
sprintf (name, "%s/%s",dir ,file_s.name);
//printf ("%s\n",name);

////////////////
FILE *fp;
fp = fopen(name, "r");
if(fp == NULL)
{
printf("\n\n Message from _A_SUBDIR");
printf("\nERROR: could not open file.\n\n");
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
GeneralRe: Console Application Pin
Maxwell Chen14-Apr-06 1:53
Maxwell Chen14-Apr-06 1:53 
GeneralRe: Console Application Pin
toxcct14-Apr-06 2:02
toxcct14-Apr-06 2:02 
GeneralRe: Console Application Pin
parichaybp14-Apr-06 2:09
parichaybp14-Apr-06 2:09 
GeneralRe: Console Application Pin
Cedric Moonen14-Apr-06 2:17
Cedric Moonen14-Apr-06 2:17 
GeneralRe: Console Application Pin
parichaybp14-Apr-06 2:19
parichaybp14-Apr-06 2:19 
GeneralRe: Console Application Pin
Cedric Moonen14-Apr-06 2:22
Cedric Moonen14-Apr-06 2:22 
GeneralRe: Console Application Pin
parichaybp14-Apr-06 2:27
parichaybp14-Apr-06 2:27 
GeneralRe: Console Application Pin
Cedric Moonen14-Apr-06 2:32
Cedric Moonen14-Apr-06 2:32 
GeneralRe: Console Application Pin
parichaybp14-Apr-06 2:34
parichaybp14-Apr-06 2:34 
GeneralRe: Console Application Pin
Cedric Moonen14-Apr-06 2:37
Cedric Moonen14-Apr-06 2:37 
GeneralRe: Console Application Pin
parichaybp14-Apr-06 2:41
parichaybp14-Apr-06 2:41 
GeneralRe: Console Application Pin
Maxwell Chen14-Apr-06 2:43
Maxwell Chen14-Apr-06 2:43 
GeneralRe: Console Application Pin
Stephen Hewitt14-Apr-06 21:20
Stephen Hewitt14-Apr-06 21:20 
GeneralRe: Console Application Pin
Maxwell Chen15-Apr-06 5:57
Maxwell Chen15-Apr-06 5:57 
GeneralRe: Console Application Pin
David Crow14-Apr-06 2:25
David Crow14-Apr-06 2:25 
GeneralRe: Console Application Pin
parichaybp14-Apr-06 2:31
parichaybp14-Apr-06 2:31 
GeneralRe: Console Application Pin
Cedric Moonen14-Apr-06 2:35
Cedric Moonen14-Apr-06 2:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.