NEED HELP WITH A PROGRAM....ANYONE PLEASE HELP!

G

genestarwing

QUESTION:
Write a program that opens and read a text file and records how many
times each word occurs in the file. Use a binary search tree modified
to store both a word and the number of times it occurs. After the
program has read the file, it should offer a menu with three choices.
the first is to list all the words along with the number of occurences.
The second is to let you enter a word, with the program reporting how
many times the word occured in the file. The third is to quit.

This quesiton is from the book C Primer Plus 5th edition by Stephen
Prata. Chapter 17 question 7. I read the chapter twice and can't figure
out how to write this program. Is there anyone out there who can give
me the code for this program. I am desperate. Maybe I could pay whoever
can give me the code.
 
M

Malcolm

QUESTION:
Write a program that opens and read a text file and records how many
times each word occurs in the file. Use a binary search tree modified
to store both a word and the number of times it occurs. After the
program has read the file, it should offer a menu with three choices.
the first is to list all the words along with the number of occurences.
The second is to let you enter a word, with the program reporting how
many times the word occured in the file. The third is to quit.

This quesiton is from the book C Primer Plus 5th edition by Stephen
Prata. Chapter 17 question 7. I read the chapter twice and can't figure
out how to write this program. Is there anyone out there who can give
me the code for this program. I am desperate. Maybe I could pay whoever
can give me the code.
Forget about the binary search tree.
Write the program so that it goes throught he file, picks out the words, and
stores the count of each word in a flat list. If it helps, set a limit of
10000 distinct words.

Then come back with what you've done and start on the binary tree bit.
 
N

Nick Keighley

QUESTION:
Write a program that opens and read a text file and records how many
times each word occurs in the file.

Maybe I could pay whoever can give me the code.

how would that help you? You learn to program by writing programs. As
another poster suggested, tackle a slightly simplified version of the
program
and then add to it.

For instance
open file
read lines
close file

the process the lines to extract words. First decide what a word is
(eg. a
sequence of non-whitespace terminated by whitespace, whitespace is
space, newline or tab).

and so on. Learn by doing, take small steps
 
C

CBFalconer

QUESTION:
Write a program that opens and read a text file and records how many
times each word occurs in the file. Use a binary search tree modified
to store both a word and the number of times it occurs. After the
program has read the file, it should offer a menu with three choices.
the first is to list all the words along with the number of occurences.
The second is to let you enter a word, with the program reporting how
many times the word occured in the file. The third is to quit.

This quesiton is from the book C Primer Plus 5th edition by Stephen
Prata. Chapter 17 question 7. I read the chapter twice and can't figure
out how to write this program. Is there anyone out there who can give
me the code for this program. I am desperate. Maybe I could pay whoever
can give me the code.

If this is for homework, the following won't help you at all. If
you just want to learn things, try the wdfreq usage demonstration
in my hashlib package. See:

<http://cbfalconer.home.att.net/download/>

--
"Our enemies are innovative and resourceful, and so are we.
They never stop thinking about new ways to harm our country
and our people, and neither do we." -- G. W. Bush.
"The people can always be brought to the bidding of the
leaders. All you have to do is tell them they are being
attacked and denounce the pacifists for lack of patriotism
and exposing the country to danger. It works the same way
in any country." --Hermann Goering.
 
O

osmium

QUESTION:
Write a program that opens and read a text file and records how many
times each word occurs in the file. Use a binary search tree modified
to store both a word and the number of times it occurs. After the
program has read the file, it should offer a menu with three choices.
the first is to list all the words along with the number of occurences.
The second is to let you enter a word, with the program reporting how
many times the word occured in the file. The third is to quit.

This quesiton is from the book C Primer Plus 5th edition by Stephen
Prata. Chapter 17 question 7. I read the chapter twice and can't figure
out how to write this program. Is there anyone out there who can give
me the code for this program. I am desperate. Maybe I could pay whoever
can give me the code.

You don't say where your problem is. I don't have that book but based on
other books by that author, I would expect that I would like it. If you
have been going through the book - not attacking it in the center, for
example - the only problem I would expect would be the requirement to use a
tree. Chapter 17 sounds like you are well into the book and doing the file
business and isolating a word should be relatively easy for you by now, or
at least doable. This is the data structure I would use for a single node
in the tree, see if it kick starts your mind. Main has a pointer to the top
node of the tree.

struct S
{
char* wd;
int ct;
struct S* left_child;
struct S* right_child;
};
 
G

genestarwing

Well maybe you could help me with the first 15 lines of the code.....i
dont know how to start the program......and no i havent gone through
the entire book. Our school was out cuz of the teachers strike happened
for 3 weeks during school period. Now in order for me to pass the
class......teacher want us to do this question. Hes on vacation now so
i cant ask him for help. Its due in two weeks and i've emailed other
teachers too but no reply yet!
 
O

osmium

Well maybe you could help me with the first 15 lines of the code.....i
dont know how to start the program......and no i havent gone through
the entire book. Our school was out cuz of the teachers strike happened
for 3 weeks during school period. Now in order for me to pass the
class......teacher want us to do this question. Hes on vacation now so
i cant ask him for help. Its due in two weeks and i've emailed other
teachers too but no reply yet!

Break the problem down into pieces. Defer the menu until much later, write
the program as though the user choice was the first choice listed, list all
the words and the counts. You need a test file, best put into the same
directory your source code will be in. You could cut and paste one of your
messages in this thread, for example, that's a reasonable sample.

#include <stdlio.h>
#include <ctype.h>
#include <string.h> -- don't feel compelled to use this

struct Node
{
char* wd;
int ct;
struct Node* left_child;
struct Node* right_child;
};
/*=========================*/
int main()
{
struct Node* tree = NULL;
char buff[1024]; /* line 16, a bonus line */

NB: This was not compiled
--------------- pseudo code -------------
open the file

loop
read a line -- perhaps gets()
if done exit the loop
isolate a word -- a function you write perhaps: char* isolate(char*
line);
add the word to the tree -- a function you write. perhaps: void
add(Node* root, char* word);
 
G

genestarwing

I am still confused on how to actually write the whole program.....help
ne one
Well maybe you could help me with the first 15 lines of the code.....i
dont know how to start the program......and no i havent gone through
the entire book. Our school was out cuz of the teachers strike happened
for 3 weeks during school period. Now in order for me to pass the
class......teacher want us to do this question. Hes on vacation now so
i cant ask him for help. Its due in two weeks and i've emailed other
teachers too but no reply yet!

Break the problem down into pieces. Defer the menu until much later, write
the program as though the user choice was the first choice listed, list all
the words and the counts. You need a test file, best put into the same
directory your source code will be in. You could cut and paste one of your
messages in this thread, for example, that's a reasonable sample.

#include <stdlio.h>
#include <ctype.h>
#include <string.h> -- don't feel compelled to use this

struct Node
{
char* wd;
int ct;
struct Node* left_child;
struct Node* right_child;
};
/*=========================*/
int main()
{
struct Node* tree = NULL;
char buff[1024]; /* line 16, a bonus line */

NB: This was not compiled
--------------- pseudo code -------------
open the file

loop
read a line -- perhaps gets()
if done exit the loop
isolate a word -- a function you write perhaps: char* isolate(char*
line);
add the word to the tree -- a function you write. perhaps: void
add(Node* root, char* word);
 
J

jjf

I am still confused on how to actually write the whole program.....help
ne one

Post your attempt and explain which parts of it you're having
difficulty with, and why.
 
O

osmium

I am still confused on how to actually write the whole program.....help
ne one

Don't worry about writing the whole program. I can see that it might sound
frightening, which is why I gave the help I did. Write the next few lines of
code and post *that*. If you post code you will almost certainly get more
help. If you can't or won't do that, your chances of getting further help
here are about zero.
 
G

genestarwing

ok so this is what i got.....but when i try to compile the prg....it
gives me this error
include<conio.h>: no such file or directory
here is my program

#include<string.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void createUp();
void createDown();
void showMenu();
void createRight();
void createLeft();
void search();
void listWords();
void searchWord();
int createBinaryTree();
long fileSize(FILE *);

struct tree
{
char *word; //The word to be stored in a node
// struct tree *left; //Left child of the node
struct tree *right; //Right child of the node
int count; //How many of these words are found by now
};

FILE *fp; //File Pointer
struct tree *node;
struct tree *sptr;
struct tree *q;
char *insdata;
char *fileName;

void main()
{
clrscr();

//Create the Binary Search Tree

if (createBinaryTree() == 0) //Show Menu
{
showMenu();
}
}

void listWords()
{
struct tree *temp;
temp = (struct tree *)malloc(sizeof(struct tree));
temp = node;

while(temp->right!=NULL)
{
printf("\n\tWord:\t%s\t\t\t\tCount:\t%d",temp->word,temp->count);
temp=temp->right;
}
temp = node;
getch();
free(temp);
}

void showMenu()
{
char ch = 'a';
while(ch!='q')
{
clrscr();
printf("\n\t\t---------------------------------");
printf("\n\t\t| Binary Search Tree |");
printf("\n\t\t---------------------------------");
printf("\n\t\t|\tl - List all words\t|");
printf("\n\t\t|\ts - Search a words\t|");
printf("\n\t\t|\tq - Quit\t\t|");
printf("\n\t\t---------------------------------");
printf("\n\t\t| Press your choise (l,s,q)\t|");
printf("\n\t\t---------------------------------\n\t\t\t\t");
ch = getche();
switch(ch)
{
case 'l':
sptr=node;
listWords();
break;
case 's':
sptr=node;
searchWord();
break;
case 'q':
free(node);
free(sptr);
free(q);
default:
break;
}
}
}

void searchWord()
{
int check=1;
char *searchWord;
printf("\n\n\t\tPlease enter the word to search: ");
gets(searchWord);
while(sptr->right !=NULL)
{
if (strcmp(searchWord,sptr->word) == 0) {
printf("\n\n\t\tWord Occurances found:%d\n",sptr->count);
getch();
check = 0;
break;
}
sptr=sptr->right; //Send sptr to its right
}
if (strcmp(searchWord,sptr->word) == 0 && check !=0) {
printf("\n\n\t\tWord Occurances found:%d\n",(*sptr).count);
getch();
check = 0;
}

if(check ==1) {
printf("\n\n\t\tNo occurances of this word found.");
getch();
}
}

int createBinaryTree()
{
char fd[1024]; //Textual Data Pointer
char *token;
int check = 0;
int counter = 1;
int true = 1;

printf("\n\t\t---------------------------------------");
printf("\n\t\t------- Frequency of Words ---------");
printf("\n\t\t---------------------------------------");
printf("\n\n\t\tPlease enter the text file name : ");
gets(fileName);

printf("\n\t\t---------------------------------------");
printf("\n\n\t\t\tReading file");
delay(500);
printf(".");
delay(100);
printf(".");
delay(100);
printf(".");
delay(100);
printf(".");
delay(100);

if ((fp = fopen(fileName, "r")) ==NULL){
printf("\n\n\t\t\tError reading file.");
getch();
return 1;
}

else {

fgets(fd, fileSize(fp) + 1, fp);
fclose(fp); //Close the file

token = strtok(fd," ");
if (token == NULL) {
printf("\n\n\t\tThe text file is empty.");
true = 0; //So that loop is not entered
getch();
return 1; //Don't show the menu
}
else {
node = (struct tree *)malloc(sizeof(struct tree));
(*node).word = token;
(*node).count = 1;
node->right = NULL;

sptr=node;
q=node;

// loop until finishied
while (true)
{
check = 0;
// extract string from string sequence
token = strtok(NULL, " ");

if (token == NULL)
{
true = 0; //Break the loop
}

insdata = token;
// printf("\nCounter %d\n",counter);
// puts(insdata);
counter++;

sptr= q;

while(sptr->right !=NULL && check==0)
{
if (strcmp(insdata,sptr->word) == 0) {
(*sptr).count++; //Increment
// printf("%d",(*sptr).count);
check=1;
}
sptr=sptr->right; //Send sptr to its right
}

if (strcmp(insdata,sptr->word) == 0) {
(*sptr).count++; //Increment
// printf("%d",(*sptr).count);
check=1;
}

if (check !=1) {
createDown();
}
sptr = node;
printf("%d",true);
}
return 0;
}
}
}

long fileSize(FILE *stream)
{
long curpos, length;
curpos = ftell(stream);
fseek(stream, 0L, SEEK_END);
length = ftell(stream);
fseek(stream, curpos, SEEK_SET);
return length;
}

void createDown()
{

struct tree *temp;
temp = (struct tree *)malloc(sizeof(struct tree));

temp->word = insdata;
(*temp).count = 1;
temp->right= NULL;

sptr->right=temp;
}
/*
void createRight()
{
if(sptr->right==NULL) {
// cout<<" "<<insdata<<" IS THE RIGHT child of "<<q->word<<endl;
sptr->right= malloc(sizeof(q));
sptr=sptr->right;
sptr->word=insdata;
sptr->count = 1;
sptr->left=NULL;
sptr->right=NULL;
q=node;
}
else {
if(strcmp(insdata,sptr->word) > 0)
{
sptr=sptr->right;
q=sptr;
if(strcmp(insdata,sptr->word) > 0)
createRight();
else
createUp();
}
else {
sptr=sptr->left;
q=sptr;
createRight();
}
}
}

void createLeft()
{
if(sptr->left==NULL)
{
// cout<<" "<<insdata<<" IS THE LEFT child of "<<q->word<<endl;
sptr->left=malloc(sizeof(q));
sptr=sptr->left;
sptr->word=insdata;
sptr->count = 1;
sptr->right=NULL;
sptr->left=NULL;
q=node;
}
else
{
if(strcmp(insdata,sptr->word) < 0)
{
sptr=sptr->left;
q=sptr;
if(strcmp(insdata,sptr->word) > 0)
createRight();
else
createLeft();
}
else
{
sptr=sptr->right;
q=sptr;
createRight();
}
}
}

void search()
{
sptr=node;
while(sptr!=NULL)
{
//This commented section will work when we will have to insert equal
data

if(strcmp(insdata,sptr->word) == 0)
{
printf("\nThis is not insertable");
printf("\nInsert child ");
cin>>insdata;
search();
break;
}
else
{

if(strcmp(insdata,sptr->word) > 0)
sptr=sptr->right;
else
sptr=sptr->left;
// }
}
sptr=node;
}

void createUp()
{
struct tree *temp = malloc(sizeof(node));

temp->word = insdata;
temp->count = 1;
temp->right= sptr;

node = temp;
}

*/

can someone look at it and let me know what i am doing wrong here
 
R

Richard Heathfield

(e-mail address removed) said:
ok so this is what i got.....but when i try to compile the prg....it
gives me this error
include<conio.h>: no such file or directory

That's because there is no such file or directory. C doesn't define such a
header, so there is no guarantee that any implementation will provide it,
nor that it will mean any particular thing if it /is/ provided.
void main()

main returns int. Always.

When you've learned that, and learned not to use gets(), you'll be ready to
ask some more questions.

can someone look at it and let me know what i am doing wrong here

I think your biggest mistake is trying to learn C from an inferior book. My
best guess is Herbert Schildt - your program seems to be full of his kind
of nonsense.
 
O

osmium

ok so this is what i got.....but when i try to compile the prg....it
gives me this error
include<conio.h>: no such file or directory
here is my program

#include<string.h>
#include<conio.h>

conio is not part of standard C. Take this out and a bunch of errors will
crop up where you have used stuff from conio.The ones I saw were probably
nice, but not really needed. clrscr() is a prettifier, eliminate it.
getch() can be replaced by something from stdio, probably by getchar().
Take this stuff out until you see no more errors caused by rewmoval of the
conio header. Then fix what comes next or post a new version of your code.

It would have been better if you had got some of it working before doing all
that typing. But what's done is done.

<big snip>
 
D

Default User

ok so this is what i got.....but when i try to compile the prg....it
gives me this error
include<conio.h>: no such file or directory
here is my program

That's an implementation-specific header. If you don't have it, there's
not much you can do. There are some similar things like ncurses that
are more commonly found, but are still non-standard from the standpoint
of this group.
clrscr();

Get rid of this, you don't need to clear the screen.


Get rid of all instances of this. You probably don't need a "pause
until continue signal", if you really can justify it we can offer some
standard replacements. It's generally the sign of a newbie to have
those.
printf("\n\t\t| Press your choise (l,s,q)\t|");
ch = getche();
switch(ch)

This is trickier. The best idea is to not use a one-key approach to
menus. Read a line of input into a string with fgets() or get the first
char with getchar() and discard the rest.




Brian
 
G

genestarwing

ok so i made some changes and i got this
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void createUp();
void createDown();
void showMenu();
void createRight();
void createLeft();
void search();
void listWords();
void searchWord();
int createBinaryTree();
long fileSize(FILE *);

struct tree
{
char *word; //The word to be stored in a node
// struct tree *left; //Left child of the node
struct tree *right; //Right child of the node
int count; //How many of these words are found by now
};

FILE *fp; //File Pointer
struct tree *node;
struct tree *sptr;
struct tree *q;
char *insdata;
char *fileName;

int main(void)
{


//Create the Binary Search Tree

if (createBinaryTree() == 0) //Show Menu
{
showMenu();
}
}

void listWords()
{
struct tree *temp;
temp = (struct tree *)malloc(sizeof(struct tree));
temp = node;

while(temp->right!=NULL)
{
printf("\n\tWord:\t%s\t\t\t\tCount:\t%d",temp->word,temp->count);
temp=temp->right;
}
temp = node;
getchar();
free(temp);
}

void showMenu()
{
char ch = 'a';
while(ch!='q')
{
clrscr();
printf("\n\t\t---------------------------------");
printf("\n\t\t| Binary Search Tree |");
printf("\n\t\t---------------------------------");
printf("\n\t\t|\tl - List all words\t|");
printf("\n\t\t|\ts - Search a words\t|");
printf("\n\t\t|\tq - Quit\t\t|");
printf("\n\t\t---------------------------------");
printf("\n\t\t| Press your choise (l,s,q)\t|");
printf("\n\t\t---------------------------------\n\t\t\t\t");
ch = getche();
switch(ch)
{
case 'l':
sptr=node;
listWords();
break;
case 's':
sptr=node;
searchWord();
break;
case 'q':
free(node);
free(sptr);
free(q);
default:
break;
}
}
}

void searchWord()
{
int check=1;
char *searchWord;
printf("\n\n\t\tPlease enter the word to search: ");
gets(searchWord);
while(sptr->right !=NULL)
{
if (strcmp(searchWord,sptr->word) == 0) {
printf("\n\n\t\tWord Occurances found:%d\n",sptr->count);
getchar();
check = 0;
break;
}
sptr=sptr->right; //Send sptr to its right
}
if (strcmp(searchWord,sptr->word) == 0 && check !=0) {
printf("\n\n\t\tWord Occurances found:%d\n",(*sptr).count);
getchar();
check = 0;
}

if(check ==1) {
printf("\n\n\t\tNo occurances of this word found.");
getchar();
}
}

int createBinaryTree()
{
char fd[1024]; //Textual Data Pointer
char *token;
int check = 0;
int counter = 1;
int true = 1;

printf("\n\t\t---------------------------------------");
printf("\n\t\t------- Frequency of Words ---------");
printf("\n\t\t---------------------------------------");
printf("\n\n\t\tPlease enter the text file name : ");
gets(fileName);

printf("\n\t\t---------------------------------------");
printf("\n\n\t\t\tReading file");
delay(500);
printf(".");
delay(100);
printf(".");
delay(100);
printf(".");
delay(100);
printf(".");
delay(100);

if ((fp = fopen(fileName, "r")) ==NULL){
printf("\n\n\t\t\tError reading file.");
getchar();
return 1;
}

else {

fgets(fd, fileSize(fp) + 1, fp);
fclose(fp); //Close the file

token = strtok(fd," ");
if (token == NULL) {
printf("\n\n\t\tThe text file is empty.");
true = 0; //So that loop is not entered
getchar();
return 1; //Don't show the menu
}
else {
node = (struct tree *)malloc(sizeof(struct tree));
(*node).word = token;
(*node).count = 1;
node->right = NULL;

sptr=node;
q=node;

// loop until finishied
while (true)
{
check = 0;
// extract string from string sequence
token = strtok(NULL, " ");

if (token == NULL)
{
true = 0; //Break the loop
}

insdata = token;
// printf("\nCounter %d\n",counter);
// puts(insdata);
counter++;

sptr= q;

while(sptr->right !=NULL && check==0)
{
if (strcmp(insdata,sptr->word) == 0) {
(*sptr).count++; //Increment
// printf("%d",(*sptr).count);
check=1;
}
sptr=sptr->right; //Send sptr to its right
}

if (strcmp(insdata,sptr->word) == 0) {
(*sptr).count++; //Increment
// printf("%d",(*sptr).count);
check=1;
}

if (check !=1) {
createDown();
}
sptr = node;
printf("%d",true);
}
return 0;
}
}
}

long fileSize(FILE *stream)
{
long curpos, length;
curpos = ftell(stream);
fseek(stream, 0L, SEEK_END);
length = ftell(stream);
fseek(stream, curpos, SEEK_SET);
return length;
}

void createDown()
{

struct tree *temp;
temp = (struct tree *)malloc(sizeof(struct tree));

temp->word = insdata;
(*temp).count = 1;
temp->right= NULL;

sptr->right=temp;
}
/*
void createRight()
{
if(sptr->right==NULL) {
// cout<<" "<<insdata<<" IS THE RIGHT child of "<<q->word<<endl;
sptr->right= malloc(sizeof(q));
sptr=sptr->right;
sptr->word=insdata;
sptr->count = 1;
sptr->left=NULL;
sptr->right=NULL;
q=node;
}
else {
if(strcmp(insdata,sptr->word) > 0)
{
sptr=sptr->right;
q=sptr;
if(strcmp(insdata,sptr->word) > 0)
createRight();
else
createUp();
}
else {
sptr=sptr->left;
q=sptr;
createRight();
}
}
}

void createLeft()
{
if(sptr->left==NULL)
{
// cout<<" "<<insdata<<" IS THE LEFT child of "<<q->word<<endl;
sptr->left=malloc(sizeof(q));
sptr=sptr->left;
sptr->word=insdata;
sptr->count = 1;
sptr->right=NULL;
sptr->left=NULL;
q=node;
}
else
{
if(strcmp(insdata,sptr->word) < 0)
{
sptr=sptr->left;
q=sptr;
if(strcmp(insdata,sptr->word) > 0)
createRight();
else
createLeft();
}
else
{
sptr=sptr->right;
q=sptr;
createRight();
}
}
}

void search()
{
sptr=node;
while(sptr!=NULL)
{
//This commented section will work when we will have to insert equal
data

if(strcmp(insdata,sptr->word) == 0)
{
printf("\nThis is not insertable");
printf("\nInsert child ");
cin>>insdata;
search();
break;
}
else
{

if(strcmp(insdata,sptr->word) > 0)
sptr=sptr->right;
else
sptr=sptr->left;
// }
}
sptr=node;
}

void createUp()
{
struct tree *temp = malloc(sizeof(node));

temp->word = insdata;
temp->count = 1;
temp->right= sptr;

node = temp;
}

*/
now when i compile it i get these errors!
/tmp/ccSZ3XYi.o(.text+0x1ed): In function `searchWord':
: the `gets' function is dangerous and should not be used.
/tmp/ccSZ3XYi.o(.text+0xa2): In function `showMenu':
: undefined reference to `clrscr'
/tmp/ccSZ3XYi.o(.text+0x137): In function `showMenu':
: undefined reference to `getche'
/tmp/ccSZ3XYi.o(.text+0x350): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x36d): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x38a): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x3a7): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x3c4): In function `createBinaryTree':
: undefined reference to `delay'
collect2: ld returned 1 exit status
 
O

osmium

now when i compile it i get these errors!
/tmp/ccSZ3XYi.o(.text+0x1ed): In function `searchWord':
: the `gets' function is dangerous and should not be used.

ignore the warning. gets is not bulletproof but this is just a student
program.
/tmp/ccSZ3XYi.o(.text+0xa2): In function `showMenu':
: undefined reference to `clrscr'

Take it out. You don't need it.
/tmp/ccSZ3XYi.o(.text+0x137): In function `showMenu':
: undefined reference to `getche'

This will be hard to resolve. Put in some way to proceed without solving the
problem. There is a lot of work ahead that is much more important than
getting this right. Replace it with getchar(), for now.
/tmp/ccSZ3XYi.o(.text+0x350): In function `createBinaryTree':
: undefined reference to `delay'

Take it out. Do you *really* need that? If you do someone can suggest a
workaround.
/tmp/ccSZ3XYi.o(.text+0x36d): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x38a): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x3a7): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x3c4): In function `createBinaryTree':
: undefined reference to `delay'
collect2: ld returned 1 exit status

Same thing repeated n times, same cure. Now you may be getting close to
seeing your first *real* error.
 
K

Keith Thompson

ok so i made some changes and i got this
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

No implementation-defined headers, good.

[snip]
now when i compile it i get these errors!
/tmp/ccSZ3XYi.o(.text+0x1ed): In function `searchWord':
: the `gets' function is dangerous and should not be used.
/tmp/ccSZ3XYi.o(.text+0xa2): In function `showMenu':
: undefined reference to `clrscr'
/tmp/ccSZ3XYi.o(.text+0x137): In function `showMenu':
: undefined reference to `getche'
/tmp/ccSZ3XYi.o(.text+0x350): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x36d): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x38a): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x3a7): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x3c4): In function `createBinaryTree':
: undefined reference to `delay'
collect2: ld returned 1 exit status

Pay attention to those errors. Don't call gets(); it's standard, but
dangerous. See question 12.23 in the comp.lang.c FAQ
<http://c-faq.com/>.

The clrscr(), getche(), and delay() functions are non-standard, and
you don't really need any of them.
 
D

Default User

Don't top-post, quotes rearranged.

Default User wrote:

ok so i made some changes and i got this

now when i compile it i get these errors!
/tmp/ccSZ3XYi.o(.text+0x1ed): In function `searchWord':
: the `gets' function is dangerous and should not be used.
/tmp/ccSZ3XYi.o(.text+0xa2): In function `showMenu':
: undefined reference to `clrscr'
/tmp/ccSZ3XYi.o(.text+0x137): In function `showMenu':
: undefined reference to `getche'
/tmp/ccSZ3XYi.o(.text+0x350): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x36d): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x38a): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x3a7): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x3c4): In function `createBinaryTree':
: undefined reference to `delay'
collect2: ld returned 1 exit status


Had you bothered to read what I took the good time and trouble to post,
you'd have seen that things like clrscr are non-standard and
(apparently) unavailable to you. I don't know what delay() is either,
but what do you need it for? Get rid of the non-standard crap.



Brian
 
G

genestarwing

Ok i think i am lost now.....the program is takin up so much of my
energy. whatever you guys are saying here is just going over my head
now!

Keith said:
ok so i made some changes and i got this
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

No implementation-defined headers, good.

[snip]
now when i compile it i get these errors!
/tmp/ccSZ3XYi.o(.text+0x1ed): In function `searchWord':
: the `gets' function is dangerous and should not be used.
/tmp/ccSZ3XYi.o(.text+0xa2): In function `showMenu':
: undefined reference to `clrscr'
/tmp/ccSZ3XYi.o(.text+0x137): In function `showMenu':
: undefined reference to `getche'
/tmp/ccSZ3XYi.o(.text+0x350): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x36d): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x38a): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x3a7): In function `createBinaryTree':
: undefined reference to `delay'
/tmp/ccSZ3XYi.o(.text+0x3c4): In function `createBinaryTree':
: undefined reference to `delay'
collect2: ld returned 1 exit status

Pay attention to those errors. Don't call gets(); it's standard, but
dangerous. See question 12.23 in the comp.lang.c FAQ
<http://c-faq.com/>.

The clrscr(), getche(), and delay() functions are non-standard, and
you don't really need any of them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top