Hi all, can you please help me solve these errors I am receiving:

q2.cpp:127: error: expected primary-expression before ‘*’ token
q2.cpp:127: error: ‘wordPointer’ was not declared in this scope

print function which is contained within the sc class:

void printDict(struct wordRecord *wordPointer) {
    // Code omitted to step through the dictionary words in turn,
    // printing each out on a new line
    
    //Step through dictionary, printing each word
    wordPointer -> root;
    while(wordPointer != NULL) {
    	printf("%s\n", wordPointer -> word);
    	wordPointer = wordPointer -> next;    	
    }
  }

calling from main function:

caseSensitiveSpellChecker sc;
  //caseSensitiveSpellChecker * sc = new caseSensitiveSpellChecker();
   
  for (int i=0; i<sizeof(words)/sizeof(char*); i++) sc->addWord(words[i]);

  printf("\nCase sensitive dictionary contents:\n");

[B]  sc.printDict(wordRecord *wordPointer);[/B]

The bold line (127) is the call which is giving me the errrors. I have already tried:

sc.printDict();
sc.printDict(struct wordRecord *wordPointer);
sc.printDict(wordRecord *wordPointer);.

and haven't any more ideas on what to do.

Thanks in advance,
Aphrodite

Recommended Answers

All 3 Replies

Well, try this one:

wordRecord test; [B]// (1)[/B]
sc.printDict(test);

(1): You can put struct at the beginning of this line, but this isn't obligated in C++.

Little correction of tux4life's code.

wordRecord test; // (1)
sc.printDict(&test);  // address operator was missing
commented: Oops! Yes! Thanks for the correction :) +18

Little correction of tux4life's code.

wordRecord test; // (1)
sc.printDict(&test);  // address operator was missing

Thanks guys, I got it working with just (wordPointer) alone as well as re-initializing the struct within the main method but your way worked best as it got rid of a triangular picture pointing left in the terminal window! However still both ways of doing this brought me a segmentation default, but I'm not sure whether this really effects anything? Not quite sure as no words are actually being printed yet I have initially got ' char* words[] = {(char*)"hello", (char*)"Womble", (char*)"goodbye"}; ' within the main method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.