Jump to content
  • Advertisement
Sign in to follow this  
forgottensoul

noobish question for c

This topic is 4606 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

here's a little noobish question: in quickbasic there is a function called locate() which allows me to start printing from a certain point on the screen. how is it done in c? thanks.

Share this post


Link to post
Share on other sites
Advertisement
There's isn't a portable standard way of doing this. In fact stdout doesn't even have to be a terminal.

If you're coding for Windows then check out SetConsoleCursorPosition.
In DOS you can probably use the gotoxy function from <conio.h>.
And in Unix the curses library provides the wmove function (or you can do it "manually" with termcaps).

Share this post


Link to post
Share on other sites
There's no standard function for that in C/C++. Without knowing the OS and compiler you're using, there's no answer.

If you're using the old Borland compilers for DOS, try the function "gotoxy" in "conio.h". With more recent compilers, such as Visual C++ creating a console application, it's a lot more difficult (weird, huh?).

Edit: doynax beat me to it, but remember that SetConsoleCursorPosition doesn't work unless you create the console yourself with AllocConsole or get the handle with GetStdHandle (STD_OUTPUT_HANDLE) (otherwise you haven't got the console handle).

Share this post


Link to post
Share on other sites
hmmm.ok. thanks...and another question...is there anything bigger than an array? because i wanted to make int location[640][480] and he told me it's too big! is there anything that will allow that? (i dont mind if any integer will be really small...even 4 bit (althought i dont think such a thing exists).

Share this post


Link to post
Share on other sites
Quote:
Original post by forgottensoul
hmmm.ok. thanks...and another question...is there anything bigger than an array? because i wanted to make int location[640][480] and he told me it's too big! is there anything that will allow that? (i dont mind if any integer will be really small...even 4 bit (althought i dont think such a thing exists).
A 640x480 array of integers is not a problem for most systems. However it generally won't fit on the stack and has to be dynamically allocated (using malloc in C).
If you're developing for 16-bit DOS then the system normally can't access more than 64 kB of data directly, in which case you'll have to look into far pointers (and far allocations) or check if your compiler supports the huge memory model.

As for the datatype itself you can save a lot of space by using a char instead of an integer. For 4-bit integers you'll have to use bitfields, but in this case they'd much less comfortable considering that you can't make arrays out of them.

Share this post


Link to post
Share on other sites
ok...i'll have to search on that thanks...one more question:

is there a way to press 2 buttons at the same time somehow? i want my character both move and swing his sword but he can do only one thing at a time...maybe i'm looking for something that is not getch() but something else...? maybe i need 2 chars to do that and a getch for each? i'm not sure really and would really appreciate any advice or help.

Share this post


Link to post
Share on other sites
You still haven't mentioned which compiler and OS you use.

getch always gets the next character in the input queue. To detect multiple simultaneous keypresses, you need to either use "GetAsyncKeyState" in Windows, or handle port 0x60 yourself (preferably through hooking interrupt 9, the keyboard interrupt). Check out the Keyboard handler extension on this page.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!