Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unresolved External Won't Go Away

Status
Not open for further replies.

ElWhapo

Programmer
Dec 1, 2004
2
0
0
US
Please help. It gives me two errors when I compile:

1. Unresolved external symbol "void __cdelc dodrop(int)...
2. Fatal Error. 1 Unresolved Externals

Here is the code:

#include <iostream.h>
#include <windows.h>
#include <conio.h>

#define BLK 0
#define RED 1
#define NON 2
#define DRW 3
#define LEFT 0x4B
#define RIGHT 0x4D
#define UP 0x48
#define DOWN 0x50
#define ESC 0x1B
#define ENTER 0x0D
#define PLAYER 0x0001 & turn

void initialize(void);
void gotoxy(int x, int y);
void drawboard(void);
void drawtop(void);
void clrtop(void);
void dodrop(int col);
void checkwin(int col,int row);
void settextcolor(int c);

char board[8][8];
int pos[2] = { 1 , 15 };
int color[2] = { 8 , 12 };
char turn;
char string[128];
int win;

HANDLE hConsole;

int main(void)
{
char inkey;

do
{
initialize();
drawboard();
clrtop();

do
{
drawtop();

do
{
inkey = _getch();
if(inkey == NULL)
{
inkey = _getch();
switch(inkey)
{
case LEFT :
if(pos[PLAYER] > 1)
{
gotoxy(pos[PLAYER],0);
cout << " ";
pos[PLAYER] -= 2;
settextcolor(color[PLAYER]);
gotoxy(pos[PLAYER],0);
cout << "*";
}
break;
case RIGHT :
if(pos[PLAYER] < 15)
{
gotoxy(pos[PLAYER],0);
cout << " ";
pos[PLAYER] += 2;
settextcolor(color[PLAYER]);
gotoxy(pos[PLAYER],0);
cout << "*";
}
break;
case DOWN :
if(board[0][(pos[PLAYER]-1) >> 1] == NON)
{
dodrop((pos[PLAYER]-1)>>1);
inkey = ENTER;
}
else
{
inkey = NULL;
}
break;
}
}
else if(inkey == ENTER)
{
if(board[0][(pos[PLAYER]-1) >> 1] == NON)
{
dodrop((pos[PLAYER]-1)>>1);
}
else
{
inkey = NULL;
}
}
} while(inkey != ESC && inkey != ENTER && win == NON);

clrtop();
turn++;
} while(inkey != ESC && turn < 64 && win == NON);

settextcolor(15);
switch(win)
{
case BLK:
gotoxy(0,0);
cout << "Black won";
break;
case RED:
gotoxy(0,0);
cout << "Red won";
break;
case DRW:
gotoxy(0,0);
cout << "Draw";
break;
default:
gotoxy(0,0);
cout << "Nobody won";
}
gotoxy(0,20);
cout << "(press ESC to exit, any key to replay)";
inkey = _getch();
gotoxy(0,20);
cout << " ";
} while(inkey != ESC);
return(0);
}

void drawboard(void)
{
int row,col;

gotoxy(0,2);

settextcolor(14);
cout << "+-+-+-+-+-+-+-+-+\n";
for(row = 0;row < 8;row++)
{
for(col = 0;col < 8;col++)
{
cout << "|";
if(board[row][col] != NON)
{
settextcolor(color[board[row][col]]);
cout << "*";
settextcolor(14);
}
else
{
cout << " ";
}
}
cout << "|\n+-+-+-+-+-+-+-+-+\n";
}
}

void initialize(void)
{
int count1,count2;
struct _CONSOLE_CURSOR_INFO PCONSOLE_CURSOR_INFO;

hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

for(count1 = 0;count1 < 8;count1++)
{
for(count2 = 0;count2 < 8;count2++)
{
board[count1][count2] = (char)NON;
}
}
turn = 0;
win = NON;

PCONSOLE_CURSOR_INFO.dwSize = 1;
PCONSOLE_CURSOR_INFO.bVisible = FALSE;
SetConsoleCursorInfo(hConsole,&PCONSOLE_CURSOR_INFO);
}

void settextcolor(int c)
{
SetConsoleTextAttribute(hConsole, c);
}

void gotoxy(int x, int y)
{
COORD dwCursorPosition;

dwCursorPosition.X = x;
dwCursorPosition.Y = y;
SetConsoleCursorPosition(hConsole,dwCursorPosition);
}

void clrtop(void)
{
gotoxy(0,0);
cout << " ";
}

void drawtop(void)
{
settextcolor(color[PLAYER]);
gotoxy(pos[PLAYER],0);
cout << "*";
}

void checkwin(int col,int row)
{
int pieces,counter;

pieces = 0;
counter = 0;
do
{
pieces++;
counter++;
} while(((row+counter) < 8) && (board[row+counter][col] == ( PLAYER )));

if(pieces > 3)
{
win = PLAYER;
return;
}

pieces = 0;
counter = 0;
do
{
pieces++;
counter--;
} while(((col+counter) > -1) && (board[row][col+counter] == ( PLAYER )));
counter = 0;
pieces--;
do
{
pieces++;
counter++;
} while(((col+counter) < 8) && (board[row][col+counter] == ( PLAYER )));
if(pieces > 3)
{
win = PLAYER;
return;
}

pieces = 0;
counter = 0;
do
{
pieces++;
counter--;
} while(((col+counter) > -1) && ((row+counter) > -1) && (board[row+counter][col+counter] == ( PLAYER )));
counter = 0;
pieces--;
do
{
pieces++;
counter++;
} while(((col+counter) < 8) && ((row+counter) < 8) && (board[row+counter][col+counter] == ( PLAYER )));
if(pieces > 3)
{
win = PLAYER;
return;
}

pieces = 0;
counter = 0;
do
{
pieces++;
counter--;
} while(((col+counter) > -1) && ((row+(-1*counter)) < 8) && (board[row+(-1*counter)][col+counter] == ( PLAYER )));
counter = 0;
pieces--;
do
{
pieces++;
counter++;
} while(((col+counter) < 8) && ((row+(-1*counter)) < 8) && (board[row+(-1*counter)][col+counter] == ( PLAYER )));
if(pieces > 3)
{
win = PLAYER;
return;
}

if(turn == 63)
{
win = DRW;
}
}
 
You declare dodrop, but never define it (i.e. code it). Since the linker cannot find it in this file, it thinks it is an external function, hence the error message.

Vincent
 
Please use [ignore]
Code:
[/ignore]
tags when posting code.

--
 
Your main() function is much larger than necessary. You should try breaking it up into smaller, more manageable functions that do more specific things. It would also make things better if you didn't use so many globals and took a more OO approach.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top