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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Borland Turbo C++ help

Status
Not open for further replies.

beyondsociety

Technical User
May 9, 2002
40
US
I have created a program that draws a box in tclite. I installed Borland Turbo C++ 2.01 and when I ran the program, I got errors.
I can't figure out whats the problem. Any help would be appreciated.

It works fine in tclite!

Heres the source code:

// Box_draw.cpp - Writing a Box for our editor

/*

The location == Left, right, and bottom
The border == Single line, double
The colors == Main color, border color

Char* border == An array of 8 characters

border[0] == Left top corner
border[1] == Top center
border[2] == Right-top corner
border[3] == Right side
border[4] == Right-bottom corner
border[5] == Bottom center
border[6] == Left-bottom corner
border[7] == Left side

*/

#include <stdio.h>
#in6clude <conio.h>

void box_draw(int lft, int top, int rgt, int btm,
char* border, int outline_clr, int contents_clr);
void startup();

int main()
{

startup();

box_draw(5,5,45,15,&quot;ÚÄ¿³ÙÄÀ³&quot;,62,23);
getch();

return 0;
}

char blanks[] = // 80 space chars

&quot; &quot;
&quot; &quot;;

void box_draw(int lft, int top, int rgt, int btm,
char* border, int outline_clr, int contents_clr)
{

/*

Coordinates must be within screen. Minimum box is 4 Columns
by 3 Rows. Drawing fails if you go to both Screen Right and
Screen Bottom.

Border chars are top-left corner, top-center, etc.,
clockwise to left corner. Valid colors are 0 to 255.

*/

// set the outline color

textattr(outline_clr);

// write the top line

gotoxy(lft,top);
putch(border[0]);

// Heres the routine thats giving me the problem

// 1.Error, expression syntax error in function box_draw
// 2.Error, undefined symbol 'i' in function box_draw

int i = lft+1; // first error
while(i<rgt) // second error
{
putch(border[1]);
i++;
}

// ------------------------------------------------

putch(border[2]);

// build the center line

blanks[0] = border[7];
i = rgt - lft;
blanks = border[3];
blanks[i+1] = 0;

// write the center line

i = top + 1;
while(i<btm)
{
gotoxy(lft,i);
cprintf(blanks);
i++;
}

// write the bottom line

gotoxy(lft,btm);
putch(border[6]);

i = lft+1;
while(i<rgt)
{

putch(border[5]);
i++;
}

putch(border[4]);

// repaint the center

if(outline_clr != contents_clr)
box_draw(lft+1,top+1,rgt-1,btm-1,
&quot; &quot;,contents_clr,contents_clr);

// repairing blanks[]

i = rgt-lft;
blanks[0] = blanks = blanks[i+1] = ' ';

gotoxy(1,1);
printf(&quot;Write the top line&quot;);

gotoxy(1,2);
printf(&quot;Write the center&quot;);

gotoxy(1,3);
printf(&quot;Write the bottom&quot;);

}

void startup()
{
textmode(C4350);
textattr(23);
clrscr();

}

// end of T.cpp



 
Instead of
int i = lft+1; // first error
while(i<rgt) // second error
{
putch(border[1]);
i++;
}

try
int i; // CHANGE
i = lft+1; // CHANGE
while(i<rgt) // second error ?
{
putch(border[1]);
i++;
}

It's not all compilers who likes that You declare-and-uses variables, if Your'e going ANSI C it's a MUST to declare first and use later. Totte
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top