PDA

View Full Version : Programming Question



legionaire45
October 23rd, 2007, 10:22 PM
Hello guys, I have a few questions about C here...

First off, I'm trying to get a graphics library out of TC (TurboC from 1988...yeah, my teacher didn't want to bother with setting up a modern compiler...nice of him) and I'm having trouble getting it properly set up. I'm pretty sure I have all the necessary and library files transferred from TC to DevC++, however it still basically gives me an error for every "far" declaration in the library. I'll get the full error message in a sec, but does anyone have an idea of what I might be missing?

Also, I'm having some issues with a program I am writing right now. Here is the code for it:

/*+--------------------------------------------+*/
/*| Tetris Version 0.1 by Morgan Cabral |*/
/*+--------------------------------------------+*/

/* Headers */
#include <stdio.h>
#include <graphics.h> /* <---- Dev C++ does not like this guy */

/* Function Blueprints */
int drawboard();
int drawpiece( int x, int y );
/* int erasepiece( int x, int y ); */

/* Variables */
int cont, redraw, key;
int driver, mode;

void main()
{
/*Detect the graphics driver shit */
driver = DETECT;
initgraph(&driver, &mode, "\\newtc\\bgi");

drawboard();

cont = 1;
redraw = 1;

/* While "cont" is equal to one, draw the piece and check to see if the user has pressed the "q" key */
while( cont == 1 )
{
drawpiece( 313, 100 );
if( kbhit() )
{
key = getch();
if( key == 'q' ) cont = 0;
}
}

}

int drawboard()
{
/* White Background box */
setfillstyle(SOLID_FILL, WHITE);
bar( 249, 99, 389, 380 );

/* Black box that gives the box a 1 pixel border */
setfillstyle(SOLID_FILL, BLACK);
bar( 250, 100, 388, 379 );
}

int drawpiece( int x, int y )
{
int key;

while( redraw = 1 )
{
for( y = 100; y <= 366; y = y + 14 )
{
setfillstyle(SOLID_FILL, RED);
bar( x, y, x + 12, y + 12);

delay( 500 );

if( y != 366 )
{
setfillstyle(SOLID_FILL, BLACK);
bar( x, y, x + 12, y + 12 );
}

if( kbhit() )
{
if( key == 'q' ) cont = 0;
}
}
}
}
*EDIT*: thats an older version of it from before I cleaned it up a bit, however it still has the same problem either way.

What I'm trying to do here is make a tetris like program (all it does right now is drop a block and stop it at the bottom of the box) that when you press "q", it all quits. However, it just stays stuck in a loop and I haven't been able to fix it. I'm sure there is some completely obvious solution that I should have seen, but at the moment I haven't had any luck fixing it. Anyone want to give me a hint? Thanks.

Edit: Fucked up TC keeps on eating my god damn programs =<. Meh, good thing I have a shitty old copy up here, although I probably should rewrite it anyway considering how much of a mess it was.... I'll post back if I need more help. If anyone has any clues on the compiler thing I'd enjoy that. :D.

Random
October 24th, 2007, 12:43 AM
couldn't you just use return 0; for the q button.

Kornman00
October 24th, 2007, 02:41 AM
1. Why don't you ever return a value in any of those functions besides main (which is void)?
2. I believe you mean "bar" not "far"
3. Why don't you ever define bar?
4. That wouldn't work Random, look where he tests for quit, its not just in the main.
5. also, cocks

Patrickssj6
October 24th, 2007, 11:41 AM
5. also, cocks
:lmao:

Classicthunder
October 24th, 2007, 12:13 PM
Needs less globals. Needs more return values. Needs more commenting for people who use XNA and DirectX. Needs more Booleans. Needs more C# or C++. Needs more logic.

Anyways this loop is always going to be true

while( redraw = 1 )
{
}

First make the '=' a '=='
Then make it possible for redraw to = 0
Or make it return under if( key == 'q' ) cont = 0

Needs more logic. Needs less global variables. Sorry but thats like the sloppiest code I've ever seen.

Gamerkd16
October 24th, 2007, 12:21 PM
Hmm....this is C? It looks very similar to java.

Chewy Gumball
October 24th, 2007, 02:27 PM
Programming languages look similar.

legionaire45
October 24th, 2007, 09:41 PM
1. Why don't you ever return a value in any of those functions besides main (which is void)?
2. I believe you mean "bar" not "far"
3. Why don't you ever define bar?
4. That wouldn't work Random, look where he tests for quit, its not just in the main.
5. also, cocks

1) Programming Teacher doesn't...want...us...to...use...return... :cry:
2) Nope, its far
3) Bar is a function of the graphics library. It draws a box filled with solid color (hence setfillstyle). It is formated bar(0,0,639,479) for a box that covers the entire screen.
5) Needs moar pussies D=.

Here are all 10,000 trillion errors from DevC++.

Compiler: Default compiler
Executing gcc.exe...
gcc.exe "C:\Dev-Cpp\TETRIS2.C" -o "C:\Dev-Cpp\TETRIS2.exe" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
In file included from C:\Dev-Cpp\TETRIS2.C:6:
C:/Dev-Cpp/include/graphics.h:244: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:246: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:247: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:249: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:250: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:251: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:252: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:253: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:254: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:255: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:257: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:258: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:259: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:260: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:261: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:262: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:263: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:264: error: expected init-declarator before '*' token
C:/Dev-Cpp/include/graphics.h:264: error: expected `,' or `;' before '*' token
C:/Dev-Cpp/include/graphics.h:265: error: expected init-declarator before "getdrivername"
C:/Dev-Cpp/include/graphics.h:265: error: expected `,' or `;' before "getdrivername"
C:/Dev-Cpp/include/graphics.h:266: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:267: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:268: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:269: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:271: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:272: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:273: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:274: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:275: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:276: error: expected init-declarator before "getmodename"
C:/Dev-Cpp/include/graphics.h:276: error: expected `,' or `;' before "getmodename"
C:/Dev-Cpp/include/graphics.h:277: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:279: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:280: error: `far' does not name a type

C:/Dev-Cpp/include/graphics.h:281: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:282: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:283: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:284: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:285: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:286: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:287: error: expected init-declarator before "grapherrormsg"
C:/Dev-Cpp/include/graphics.h:287: error: expected `,' or `;' before "grapherrormsg"
C:/Dev-Cpp/include/graphics.h:288: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:289: error: expected init-declarator before '*' token

C:/Dev-Cpp/include/graphics.h:289: error: expected `,' or `;' before '*' token

C:/Dev-Cpp/include/graphics.h:290: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:291: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:292: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:295: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:296: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:297: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:298: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:299: error: `far' does not name a type

C:/Dev-Cpp/include/graphics.h:300: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:301: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:302: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:303: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:304: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:306: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:308: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:309: error: `far' does not name a type

C:/Dev-Cpp/include/graphics.h:310: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:311: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:312: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:314: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:315: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:316: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:317: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:318: error: `far' does not name a type

C:/Dev-Cpp/include/graphics.h:319: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:320: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:321: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:322: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:323: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:325: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:326: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:328: error: `far' does not name a type

C:/Dev-Cpp/include/graphics.h:329: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:330: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:332: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:334: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:335: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:336: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:337: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:342: error: `far' does not name a type

C:/Dev-Cpp/include/graphics.h:354: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:355: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:356: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:357: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:358: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:359: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:365: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:375: error: `far' does not name a type

C:/Dev-Cpp/include/graphics.h:376: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:377: error: `far' does not name a type
C:/Dev-Cpp/include/graphics.h:378: error: `far' does not name a type
C:\Dev-Cpp\TETRIS2.C:18: error: `main' must return `int'
C:\Dev-Cpp\TETRIS2.C: In function `int main(...)':

C:\Dev-Cpp\TETRIS2.C:20: error: `initgraph' undeclared (first use this function)
C:\Dev-Cpp\TETRIS2.C:20: error: (Each undeclared identifier is reported only once for each function it appears in.)
C:\Dev-Cpp\TETRIS2.C:30: error: `kbhit' undeclared (first use this function)
C:\Dev-Cpp\TETRIS2.C:32: error: `getch' undeclared (first use this function)

C:\Dev-Cpp\TETRIS2.C: In function `int drawboard()':
C:\Dev-Cpp\TETRIS2.C:41: error: `setfillstyle' undeclared (first use this function)
C:\Dev-Cpp\TETRIS2.C:42: error: `bar' undeclared (first use this function)

C:\Dev-Cpp\TETRIS2.C: In function `int drawpiece(int, int)':
C:\Dev-Cpp\TETRIS2.C:56: error: `setfillstyle' undeclared (first use this function)
C:\Dev-Cpp\TETRIS2.C:57: error: `bar' undeclared (first use this function)
C:\Dev-Cpp\TETRIS2.C:59: error: `delay' undeclared (first use this function)
C:\Dev-Cpp\TETRIS2.C:67: error: `kbhit' undeclared (first use this function)

Execution terminated
And yeah, the missing equal sign was me editing the app late at night xD. I fixed that earlier today but it still wouldn't properly loop, so I went ahead and tried using return and of coarse, it works now (although you have to tap q twice in quick succession). I think I have an idea of how to get it to work without return though.

4RT1LL3RY
October 24th, 2007, 10:32 PM
You forgot
#include <conio.h>
Thats where getch is.
Also, would you like borland? Its much better in my opinion for C++, not sure about C though.

legionaire45
October 24th, 2007, 10:51 PM
You forgot
#include <conio.h>
Thats where getch is.
Also, would you like borland? Its much better in my opinion for C++, not sure about C though.
That didn't help =/.

It is reporting that the issue is with graphics.h (my dated graphics library). Dev C++ has conio.h included already and even with the circa-1991 version of it I'm still getting the same errors. I've never had to include conio.h when I'm using getch(); in the past either, so I'm pretty sure it's part of stdio.h.

Thanks for the help though :D. I'm pretty sure that Turbo C is a borland product already. I'll keep trying to get Dev C++ to work but at this point I think the library is incompatible =/. Rather annoying too, I don't understand why everyone is so afraid of DirectX or OpenGL >=|. God, a working/compatible modern god damn compiler would be heaven right now.

legionaire45
October 24th, 2007, 11:40 PM
Lol double post, but I got the program working as it should be :D. Thanks for all the suggestions. Now I just need that fucking compiler fixed :D.

Kybo_Ren
October 25th, 2007, 03:08 AM
The MinGW compiler doesn't need to be fixed, it's a port of g++, which is arguably the most stable compiler out there. The compiler is fine, but tbqh your programming form and style are awfully dated. You really need to modernize what you're using. conio.h is a highly unsupported, 3-rd party header file with a library that is just *terrible*. I don't mean to bash on you here, but you should be writing C++ for God's sake, not dated C!

legionaire45
October 25th, 2007, 09:30 PM
The MinGW compiler doesn't need to be fixed, it's a port of g++, which is arguably the most stable compiler out there. The compiler is fine, but tbqh your programming form and style are awfully dated. You really need to modernize what you're using. conio.h is a highly unsupported, 3-rd party header file with a library that is just *terrible*. I don't mean to bash on you here, but you should be writing C++ for God's sake, not dated C!
Heh, yeah, that about describes it exactly. I don't think my programming teacher has actually kept up with anything about programming in the past 10 years considering how dated our compiler is. Do you have any recommendations for a good C++ book or tutorial site? I think I'd rather fix my mistakes before they become pains in the ass to fix down the road...

One thing though, by "fix the fucking compiler" I meant get the archaic graphics library to work. I used DevC++ a few years ago to play around with C++ (basically hello world programs) and I found it much faster then Microsoft's at the time version of Visual C++ Express. That's probably changed by now though considering I have heard good things of visual C++ 6 or whatever.

Kybo_Ren
October 26th, 2007, 01:47 AM
Yeah I have a few good books. To start with, try C++ for the Absolute Beginner. Hang around on forums like http://www.cpp-home.com/forum/index.php and http://cboard.cprogramming.com/. Those are some of the best programming fora out there and you will learn *so* much over at either of these.

From then on I can recommend getting Bjarne's own book, The C++ Programming Language (3rd ed.), and as a reference, Schildt's The Complete Reference: C++ (4th ed.)

But mainly just programming fora and keeping in touch with experienced programmers can help more than you can imagine.

legionaire45
October 26th, 2007, 08:34 PM
Yeah I have a few good books. To start with, try C++ for the Absolute Beginner. Hang around on forums like http://www.cpp-home.com/forum/index.php and http://cboard.cprogramming.com/. Those are some of the best programming fora out there and you will learn *so* much over at either of these.

From then on I can recommend getting Bjarne's own book, The C++ Programming Language (3rd ed.), and as a reference, Schildt's The Complete Reference: C++ (4th ed.)

But mainly just programming fora and keeping in touch with experienced programmers can help more than you can imagine.
Thanks :).

Classicthunder
October 26th, 2007, 09:33 PM
I suggest C# personally. I found incredibly imaginative ways to hook up pointer so that it seem editing variables would effect random variables in C++. Had to keep making info classes to pass information from pointer to pointer. Very annoying. Anyways the ditel and ditel for C# and C++ are very good references.