#includeThis program almost compiles with GNU gcc (and the TurboC library), and almost works as-is, except for a couple of points:
#includevoid
main (void)
{
time_t t, newt;
int i = 0, x, y;
time (&t);
clrscr ();
cprintf ("Hit any key to continue: ");
x = wherex ();
y = wherey ();
// Wait for a keypress, flashing the message
// "I'm waiting!" on and off once per second.
// After any key is hit, display "Hello, world!"
while (!kbhit ())
{
time (&newt);
if (t != newt)
{
t = newt;
i++;
if (0 == (i & 1))
cprintf ("I\'m waiting!");
clreol ();
gotoxy (x, y);
}
}
getch ();
cprintf ("\r\nHello, world!\r\n");
}
- You will want to add the following statement at the very end of the program:
- The "Hello, world!" message won't actually be seen, because the you have to end with will instantly restore whatever was on the screen prior to running the program. So, you might want to add another getch() textmode(EXITMODE) printing the "Hello, world!" message.
- GNU gcc expects main to be of type int rather than void, and of course you can't actually use int because of the automatic conversion of integer datatypes. So use gint instead.
- textmode (EXITMODE);
gcc -o Hello Hello.c -lTurboC -lncursesCompiling without warnings is actually a little unusual, because there are quite a few things that can cause non-fatal warning messages. See the trouble-shooting section for more detail.
xterm +sb -e Hello
No comments:
Post a Comment