Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Whats wrong!?!?!?

Author
Message
Wik
21
Years of Service
User Offline
Joined: 21st May 2003
Location: CT, United States
Posted: 21st Mar 2004 02:39 Edited at: 21st Mar 2004 02:39
Ok, I'm begining C/C++ and I've got DJGPP.
I have some code:

And whenever I try to compile it gives an error:
Quote: "gcc screen2.c
screen2.c: In function rectangle
screen2.c:56: error: 'fb' undeclared (first use in this function)
screen2.c:56: error: (Each undeclared identifier is reported only once
screen2.c:56: error: for each function it appears in.)
"

I have no idea what's wrong and have wracked my brains out.

All help would be greatly appreciated


Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 21st Mar 2004 02:51
I dont wish to sound rude but maybe this should go on a C++ forum maybe

Always have, never will =)
Preston C
21
Years of Service
User Offline
Joined: 16th May 2003
Location: Penn State University Park
Posted: 21st Mar 2004 02:52
Well then, let me give a small guess...

The array may only be declared in int main and not in int rectangle. Today I had some problems with arrays not working inside other functions at all and that could be it. Maybe you could use some pointers in there.

Cheers,
Preston

[PS] Ugh, third post of the day, cant get distracted...


Intel Celeron 1.3 Ghrz 512MB Ram NVIDIA GeForceFX 5200 128MB
Wik
21
Years of Service
User Offline
Joined: 21st May 2003
Location: CT, United States
Posted: 21st Mar 2004 03:02
But it is in int main.

@pet rat: sorry, I thought I'd try here as there are many C/C++ programmers.


zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 21st Mar 2004 04:07 Edited at: 21st Mar 2004 04:08
But, it is not automatically global. C/C++ is not Dark BASIC.

Boy howdy, you're in for a world of hurt. BASIC makes so many assumptions that you have to do manually in C/C++.
--
TAZ

Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 21st Mar 2004 04:25
Yep, it's a scoping issue. The variable char fb[320*200] is only relevant to the int Main function, you have to define it as global by placing it outside the function. So at the top of the source:




"Computers are useless they can only give you answers."
Wik
21
Years of Service
User Offline
Joined: 21st May 2003
Location: CT, United States
Posted: 21st Mar 2004 04:25 Edited at: 21st Mar 2004 04:36
That would explain it. I'll try to fix it.

Thanks

[b][EDIT]Well, that was easyer than I though, just had to move the declaration out of a function


Wik
21
Years of Service
User Offline
Joined: 21st May 2003
Location: CT, United States
Posted: 21st Mar 2004 04:47
One more question:
Is there an equivelent to the timer() function or something to control the flow of the program?


Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 21st Mar 2004 07:07
"#include <time.h>" the Time Header file and then you can call all sorts of nifty timing commands like time(), ctime(), gmtime() etc. Do a google search and you should be able to find some good references for what each does and their parameters.


"Computers are useless they can only give you answers."
Wik
21
Years of Service
User Offline
Joined: 21st May 2003
Location: CT, United States
Posted: 21st Mar 2004 17:31
Thanks


Gery
20
Years of Service
User Offline
Joined: 24th Jan 2004
Location:
Posted: 21st Mar 2004 20:59
where to find a good hand-book to c++?

Éljen Magyarország! Jawoll
Preston C
21
Years of Service
User Offline
Joined: 16th May 2003
Location: Penn State University Park
Posted: 21st Mar 2004 21:06
Well then Wik, sorry to use your thread for my own gain for a bit but I just can't figure this one out...



Modified a bit from the DirectX 9.0 SDK's Vertices Tutorial. I'm trying to use global multi-dimensional arrays to store data for one vertex. But whenever I try to store a value to a few spots in the the array and I build the exe, I get this:



So its basically re creating the array, but I dont want it to do that. Any thoughts?

@Ge3ri: Amazon.com, great place to find some books of any kind, then theres always Barnes and Nobles you can turn too, as well as Walden Books.

Cheers,
Preston


Intel Celeron 1.3 Ghrz 512MB Ram NVIDIA GeForceFX 5200 128MB
Gery
20
Years of Service
User Offline
Joined: 24th Jan 2004
Location:
Posted: 21st Mar 2004 21:13
in amazon is just english books.

Éljen Magyarország! Jawoll
Wik
21
Years of Service
User Offline
Joined: 21st May 2003
Location: CT, United States
Posted: 22nd Mar 2004 01:24
Sorrym one last thing...
How do you detect keypresses?


Arkheii
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 22nd Mar 2004 08:16
Quote: "How do you detect keypresses?"


I remember including stdio.h and using getchar() in DOS, but in windows I think you'd have to make a function of LRESULT CALLBACK wndProc(hWnd, msg, wParam, lParam), and if msg==WM_KEYDOWN then wParam is the key being pressed. But that's in windows, of course.


"Story in a game is like story in a porn movie. It's expected to be there, but it's not that important." - John Carmack
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 22nd Mar 2004 13:04
Quote: "Well then Wik, sorry to use your thread for my own gain for a bit but I just can't figure this one out..."


Preston, while it's fine to declare variables with a global scope at the top of a file, it isn't acceptable to initialize them there. The top of your file is basically letting the compiler know of things existance, it never actually runs through the statements there - it's a bit hard to explain - Anyway, you must place the following 3 lines inside an actual function to get it to work:



Create a new function for setting up the vertex data if you'd like, just don't put them up the top.


Quote: "How do you detect keypresses?"


It depends. Are you creating a console application or a Windows 32 program? There are several ways, some easier then others.


"Computers are useless they can only give you answers."
Wik
21
Years of Service
User Offline
Joined: 21st May 2003
Location: CT, United States
Posted: 22nd Mar 2004 22:43
I think it's a Win32 program. Its in the command prompt but is compiled using DJGPP.


Wik
21
Years of Service
User Offline
Joined: 21st May 2003
Location: CT, United States
Posted: 24th Mar 2004 00:26
Hmmmmm...
Getchar() requires the enter key to be pressed and the program tries to scroll itself. Also the escape key doesnt work right.

Getch()/Getche() requires a key to be pressed in order for my while loop to work



All help would be greatly appreciated.


Login to post a reply

Server time is: 2024-09-21 13:46:46
Your offset time is: 2024-09-21 13:46:46