Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
REDIM equivalent in C?
#11
I think I get it. Smile
Okay, next question - is there a function that is the equivalent of INKEY$?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#12
Not exactly, but you can do some workarounds with this:

Code:
#include <conio.h>
#include <stdio.h>

int main(void)
{
   char c;

   printf("Press 's' to exit \n");

   do
   {

      /* If there is a character in the keyboard buffer... */
      if (kbhit())
      {
         c = getch();  /* get it */
      }
   } while (c!='s');
}

The above code works in Borland C, and I am not sure about it is portable or not (try it in your compiler, it may work). That "kbhit" stuff sounds quite nasty, so...

...for real usability and portability, you better learn to work with a keyboard handler, for example allegro's Wink

Allegro's work like this:

Code:
#include <allegro.h>
#include <stdio.h>

int main(void)
{
   allegro_init();
   install_keyboard();  /* Installs the keyboard handler */

   printf("Press s to exit\n");

   while(!key[KEY_S]);

   remove_keyboard();
   allegro_exit();
}
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#13
Erm...don't you need END_OF_MAIN() at the end of an allegro app?
Also, I'm using mingw32...so no conio.h for me. Sad
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#14
Yeah, you need that END_OF_MAIN; I was testing my code in DJGPP (like your compiler but for MSDOS) and you don't need it Tongue

Anyways, I don't know another replacement. Use Allegro's Smile
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#15
Btw, what's with that WHILE statement? No following statement or code block...huh?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#16
Look at this:

The while statement is

Code:
while (<condition>)
   instruction;

Instruction can be a single instruction:

Code:
while(!key[KEY_S])
   rectfill(screen, 0, 0, SCREEN_H, SCREEN_W, makecol(rand()&255,rand()&255,rand()&255));

or an instruction block:

Code:
while(!key[KEY_S])
{
   // Stuff here
}

I just used the simplest instruction: ";" which does nothing:

Code:
while(!key[KEY_S])
   ;

Note that while(<condition>) is not followed by a colon but by an instruction. My instruction is null, so the following colon is the separator after a null instruction. I am used to write it in a single line:

Code:
while(!key[KEY_S]);

that while just waits until 's' is pressed, does nothing in the meantime, just wait. In QB:

Code:
WHILE (NOT key(KEY_S)):WEND

What I like most about C is the flexibility in its syntax.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#17
Ah! I see. What I like about C, also, is that you can do a lot on one line. :wink:
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)