954,141 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Faulty programme!!!

help. this programme shows linking error!!! :cry: :cry: :cry:

#include "diction.h"

int Dictionary::find_word(char *s)
{
char word[81];
for (int i = 0; i < nwords; ++i)
if (stricmp(words[i].get_word(word),s) == 0)
return i;

return -1;
}

void Dictionary::add_def(char *word, char **def)
{
if (nwords < Maxwords)
{
words[nwords].put_word(word);
while (*def != 0)
words[nwords].add_meaning(*def++);
++nwords;
}
}

int Dictionary::get_def(char *word, char **def)
{
char meaning[81];
int nw = 0;
int word_idx = find_word(word);
if (word_idx >= 0)
{
while (words[word_idx].get_meaning(nw,meaning) != 0)
{
def[nw] = new char[strlen(meaning)+1];
strcpy(def[nw++],meaning);
}
def[nw] = 0;
}

return nw;
}

shouvik
Newbie Poster
16 posts since Aug 2004
Reputation Points: 11
Solved Threads: 0
 

What's the error? And this looks like just a fragment of the program, as it has no main(). Maybe something else is needed?

Chainsaw
Posting Pro in Training
436 posts since Jun 2004
Reputation Points: 36
Solved Threads: 11
 

yes, a perfectly C program must have a main() function.

XianBin
Newbie Poster
24 posts since Aug 2004
Reputation Points: 15
Solved Threads: 0
 
yes, a perfectly C program must have a main() function.


Yeah but how do i write the main. I just dont seem to get it???

shouvik
Newbie Poster
16 posts since Aug 2004
Reputation Points: 11
Solved Threads: 0
 

help. this programme shows linking error!!! :cry: :cry: :cry:

#include "diction.h"

int Dictionary::find_word(char *s) { char word[81]; for (int i = 0; i < nwords; ++i) if (stricmp(words[i].get_word(word),s) == 0) return i;

return -1; }

void Dictionary::add_def(char *word, char **def) { if (nwords < Maxwords) { words[nwords].put_word(word); while (*def != 0) words[nwords].add_meaning(*def++); ++nwords; } }

int Dictionary::get_def(char *word, char **def) { char meaning[81]; int nw = 0; int word_idx = find_word(word); if (word_idx >= 0) { while (words[word_idx].get_meaning(nw,meaning) != 0) { def[nw] = new char[strlen(meaning)+1]; strcpy(def[nw++],meaning); } def[nw] = 0; }

return nw; }

I am a first year student in c++ but maybe have you tried the create a Header file first with the following

#ifndef diction.h
#define diction.h

your Header file declarations
then add at the end

#endif

Pietro
Newbie Poster
5 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You