Newbie looking for someone to check over code

Newbie looking for someone to check over code

Post by Mark Muni » Wed, 11 Aug 1999 04:00:00



O.K.  I am trying to get an output that looks something like:

Input up to 10 numbers or STOP to quit.
XXXXXXXXXX (input)
The number you want is:
XXXXXXXXXX (output)

It is on the premise that someone who is lazy and does not want to look up
the letters given as a phone number can use this program to convert a
pnemonic phone number to an actual numeric one.  My code looks like (caution
I put the whole thing in there):

Function Prototypes & Standard Library Files
#include <iostream.h>
#include <fstream.h>
#include <string.h>

void inChar(ofstream& echodata, char phword[]);
void numConvert(char phword[], ofstream& echodata);
void printNum(ofstream&, char phnumber[]);

Main Function
int main()
{
 ofstream echodata;
 char phword[11];
 char phnumber[11];
 int quit = 1;
 echodata.open("echodata.txt");

 while (quit != 0)
 {
  inChar(echodata, phword);
  numConvert(phword, echodata);
  printNum(echodata, phnumber);
 }

 return 0;

Quote:}

inChar Function
void inChar(ofstream& echodata, char phword[])
{
 int length = 11;
 while (length > 10)
 {
  cout << "Input up to 10 characters or STOP to quit." << endl;
  echodata << "Input up to 10 characters or STOP to quit." << endl;
  cin.get(phword, 11);
  cin.ignore (100, '\n');
  echodata << endl;

  if (length > 10)
  {
   cout << "You have entered too many characters!" << endl;
   echodata << "You have entered too many characters!" << endl;
   cout << "Input up to 10 characters or STOP to quit." << endl;
   echodata << "Input up to 10 characters or STOP to quit." << endl;
  }

  cout << "The number for the letters " << phword << " is:" << endl;
  echodata << "The number for the letters " << phword << " is:" << endl;
 }

Quote:}

This is the numConvert Function:
void numConvert(char phword[])
{
 int number;
 for (number = 0; number < 10; number++)
 {
  switch(phword[number])
  {
  case 'A':
  case 'B':
  case 'C': phword[number] = '2';
   break;
  case 'D':
  case 'E':
  case 'F': phword[number] = '3';
   break;
  case 'G':
  case 'H':
  case 'I': phword[number] = '4';
   break;
  case 'J':
  case 'K':
  case 'L': phword[number] = '5';
   break;
  case 'M':
  case 'N':
  case 'O': phword[number] = '6';
   break;
  case 'P':
  case 'R':
  case 'S': phword[number] = '7';
   break;
  case 'T':
  case 'U':
  case 'V': phword[number] = '8';
   break;
  case 'W':
  case 'X':
  case 'Y': phword[number] = '9';
   break;
  default: phword[number] = phword[number];
  }
 }

Quote:}

numPrint Function
void numPrint(ofstream& echodata, char phword[])
{
 cout << phword << endl;
 echodata << phword << endl;

Quote:}

The code will compile, but I am getting errors when I try to run it.  I am
also including the errors that I got.  I am using MSVC++ 6.0.

Linking...
P2.obj : error LNK2001: unresolved external symbol "void __cdecl

P2.obj : error LNK2001: unresolved external symbol "void __cdecl
numConvert(char * const,class ofstream &)"

Debug/P2.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

P2.exe - 3 error(s), 0 warning(s)

Again, sorry for the length but some helpful hints on fixing this would
help.


 
 
 

Newbie looking for someone to check over code

Post by David Harm » Wed, 11 Aug 1999 04:00:00


On Tue, 10 Aug 1999 01:55:51 GMT in comp.lang.c++, "Mark Muniz"


>P2.obj : error LNK2001: unresolved external symbol "void __cdecl
>printNum(class ofstream &,char * const)"

I notice that you declare and call a function:
Quote:>void printNum(ofstream&, char phnumber[]);

but then when we get to the point where we would expect to see that
function you have instead:

Quote:>void numPrint(ofstream& echodata, char phword[])

With different names, these are obviously unrelated to each other as far
as the compiler is concerned, so it is no supprise that it complains
that the function is missing.

Quote:>P2.obj : error LNK2001: unresolved external symbol "void __cdecl
>numConvert(char * const,class ofstream &)"

I notice that you declare and call a function:
Quote:>void numConvert(char phword[], ofstream& echodata);

but then when we get to the point where we would expect to see that
function you have instead:

Quote:>void numConvert(char phword[])

Now this is a little closer inasmuch as the name is right;  but with
different arguments it is still a different C++ function.  So, it is
still no suprise that the compiler complains about the missing one.