Help 'C' Guru's

In my studies of 'C' I've been trying to tweek a program to add an
if -else statement and get away from goto statement. The one I have
chosen doesn't seem to work and I can't figure out why...maybe you guys
can see something I missed. The if-else statement near the bottom is the
culprit. I can get the program to run the if part but, fails on the else
part. Its as though  that part of the code isn't being read if "if" is
false. I've tried it with
 if(drop!=BOTTOM_ROW) with conditions if an else examines swaped around.
 if(drop<BOTTOM_ROW) with conditions if an else examines swaped around.
And with what is currently in the code to no availl...any help would be
appreciated.
NOTE: The program compiles without error and runs everything but the
else statement.


Here is the source code

#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>

#define VIDEO 0x10          //Video interrupt
#define COLS 80             //Screen width
#define ROWS 25             //Screen rows
#define BOTTOM_ROW 24       //Bottom row
#define CENTER_COL 39       //Center colomn
#define BOMB 162            //Bomb character
#define PAUSE 3000000       //Pause time (0 - 16,000,000)

void cls(void);
void locate(int col,int row);

int main()
{
    int drop;
    unsigned long p;

    cls();
    locate(CENTER_COL-3,BOTTOM_ROW);
    printf("PLANET BOB");
    locate(0,0);
    printf("Press ENTER to drop nuclear weapon:");
    getch();

//This loop drops the bomb down to the city, slowly
    for(drop=0;drop<BOTTOM_ROW;drop++)
    {
        locate(CENTER_COL,drop);
        printf("%c",BOMB);
        for(p=0;p<PAUSE;p++)        //Pause

              if(kbhit())
                {
                break;
            }

 printf("\b ");      //Erases trailing bombs, illusion of animation
    }
      if(drop==BOTTOM_ROW)
         {
              locate(CENTER_COL-3,BOTTOM_ROW);
              printf("BOOM!!!\a\n");
              exit(0);
         }
      else
        {
             locate(0,24);
             printf("you saved planet BOB!!!\a \n");
             getch();
        }
    return;
}
void cls(void)                    // Clear screen function
{
 union REGS regs;

 regs.h.ah=0x06;
 regs.h.al=0x00;
 regs.h.bh=0x07;
 regs.h.ch=0x00;
 regs.h.cl=0x00;
 regs.h.dh=ROWS-1;
 regs.h.dl=COLS-1;
 int86(VIDEO,&regs,&regs);

 locate(0,0);
}
void locate(int col,int row)
{
 union REGS regs;

 regs.h.ah=0x02;
 regs.h.bh=0x00;
 regs.h.dh=row;
 regs.h.dl=col;
 int86(VIDEO,&regs,&regs);

}
0
jim
3/19/2003 9:53:00 PM
grc.techtalk 27358 articles. 1 followers. Follow

5 Replies
508 Views

Similar Articles

[PageSpeed] 2

"jim" <jamesr.jrg@verizon.net> wrote in message
news:b5ap0o$e1b$1@news.grc.com...
> In my studies of 'C' I've been trying to tweek a program to add an
> if -else statement and get away from goto statement. The one I have
snip...

I'm far from a guru -- maybe ten years ago when I was doing it every day but
certainly not now. Anyway, a quick glance and some foggy memories suggest
that the way you have written the FOR "drop" loop it will terminate before
the IF "drop" condition can become true -- try doing a print of the "drop"
value as it increments and see how high it gets. Don't even have a C
compiler installed on any of my systems so I can't check it myself.
--
John McGaw
[Knoxville, TN, USA]

Return address will not work. Please
reply in group or through my website:
http://johnmcgaw.com
0
John
3/19/2003 10:04:00 PM
This is not working because drop always == BOTTOM_ROW when the for loop 
exits because there is no way out of the loop except for drop == BOTTOM_ROW.

You have a break in the pause loop for when the user hits a key - you 
need the same code to exit the drop loop


for (drop = 0; drop < BOTTOM_ROW; ++drop)
{
     ...

     for (p = 0; p < PAUSE; ++p)
     {
         if (kbhit())
         {
             break;
         {
     }

     ...

     if (kbhit())
     {
         break;
     }
}


calling kbhit() does not remove the fact a key was hit - the key stays 
in the buffer.
0
Pete
3/19/2003 11:02:00 PM
thanks Pete..that works ;)

Jim
"Pete" <peterlbirch@hotmail.com> wrote in message
news:3E78F715.1030503@hotmail.com...
This is not working because drop always == BOTTOM_ROW when the for loop
exits because there is no way out of the loop except for drop ==
BOTTOM_ROW.

You have a break in the pause loop for when the user hits a key - you
need the same code to exit the drop loop


for (drop = 0; drop < BOTTOM_ROW; ++drop)
{
     ...

     for (p = 0; p < PAUSE; ++p)
     {
         if (kbhit())
         {
             break;
         {
     }

     ...

     if (kbhit())
     {
         break;
     }
}


calling kbhit() does not remove the fact a key was hit - the key stays
in the buffer.
0
jim
3/19/2003 11:12:00 PM

"Pete" <peterlbirch@hotmail.com> wrote in message
news:3E78F715.1030503@hotmail.com...


calling kbhit() does not remove the fact a key was hit - the key stays
in the buffer.


====================================================

Isn't that what the getch(); in the else statement for?

Jim
0
jim
3/19/2003 11:21:00 PM
Yes - I was just saying that it can be called many times in a row and it 
will pickup the same keypress.

jim wrote:
> Isn't that what the getch(); in the else statement for?
> 
0
Pete
3/19/2003 11:52:00 PM
Reply:

Similar Artilces:

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\NW.pm to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified NW.pm, it calls t/uni/case.pl, that, in case.pl, (when the path separators are '\'), the $file is '..\lib\unicore\To\Lower.pl' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

LINQ -- how to do where x in ('a', 'b','c')
How do I write a LINQ expression that does the following: select * from SomeTable where SomeColumn in ('a', 'b','c')  Jay There is no IN operator in LINQ (yet), but you can use Contains instead: http://www.devauthority.com/blogs/jwooley/archive/2007/08/06/69922.aspx Jos...

Help with 'do until' ......... 'Loop'
Hello Everyone, I am writing a program to search for customers on a database.  I am having a bit of a problem with my do until ..... loop routines. I have posted the code below for you to look at and correct me. I am using VB on VS 2005 and Access Database. The end user will enter the customers name (Whole or part of ) in to a textbox and click the button 'Find', once the checks have been done to make sure there is something in the textbox it will then call this routine Search_Customer(ByVal Customer_Name).  The ByVal Customer_name will have the text...

'''
Name: L Lachowsky Email: e2brutus_10atyahoodotcom Product: Firefox Summary: ''' Comments: why duddn this surprise me... I change default server from IE to Mozilla, and then i get error messages. well, shud I decide to not get on my computer with Mozilla..or shud I risk security breeches with IE....hmmm at least i can get on the internet with IE Browser Details: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this fee...

Help! I cannot access the DataGrid's ItemTemplate's LinkButton's Text Atrribute 's Value!!!!!!!!!!!
I write a datagrid's ItemDataBound method as follows:   private void dgTable_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)  {   if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)   {    if(!isRole("Manager"))    {     LinkButton tmp = (LinkButton)e.Item.FindControl("lbPassed");     if(tmp.Text == "Passed")     {      ((LinkBu...

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

table_info('','','','%') cannot return any types
I was recently confirming table_info special cases and discovered the case for getting table_types cannot work. table_info('','','','%') should return a list of table types but it returns a list of empty strings instead: my @types = $h->tables('', '', '', '%'); print "all types:\n", join("xxx\n", @types), "\n"; # should output something like: # "dbo" # "INFORMATION_SCHEMA" # "sys" # and actually outputs: xxx xxx It seems to be down to the following ...

It's the fastest ''firefox'' i've ever had!!!:)
Name: Blagovest Email: blago_944atabvdotbg Product: Firefox Summary: It's the fastest ''firefox'' i've ever had!!!:) Comments: I's a great product!I'm really amazed! Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1b1) Gecko/20081007 Firefox/3.1b1 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to see it. ...

Guru's..?? Any do's and/or dont's for Zfd4 and Citrix..?
We've got a nw6/sp5 network with GW 6.5, bm3.7 and zfd 4.01 up'n'running.. Now we're adding a citrix server ( win2003) to the mix, will supply a couple off app's to users over the internal VPN in another city. Probably we'll skip the AD phase since we can not see any app and/or user with the need for AD. So,, any special considorations..? tip's'tricks..? known issues...? t.i.a... On Mon, 16 Aug 2004 15:57:10 GMT, Emerson wrote: > So,, any special considorations..? tip's'tricks..? known issues...? biggest one... zfd4.x d...

What's the difference between 'Build' and 'Publish'
Greetings....this subject might belong in one of the Visual Studio forums but it's so danged noob-sque.... I'm particularly confused by the 'Precompiled' term in the Publish operation. I'm interested in the path of least resistance between my VS project and my public IIS webserver. thx--steve...  Build means creating the assembly of the project ( .dll or .exe file) wich contains MSIL and a manifest file. When you publish your project u just produce the structure of your folder without producing a .dll file when you want to deploy your Web Project. ...

'b'..'a'
Hello. I'm using defferent 5.6.0's for Win32. I wonder wheter following behaviour is intentional or not: d:\>perl -e "print 'b'..'c'" bc d:\>perl -e "print 'b'..'a'" bcdefghijklmnopqrstuvwxyz I expected empty list in latter case, like in perl -e "print 'bb'..'a'" <!ENTITY Vadim REALLIFE "Vadim V.Konovalov, St.Petersburg, Russia"> &Vadim; On Wed, Sep 20, 2000 at 03:14:41PM +0400, Konovalov, Vadim wrote: > Hello. > > I'm using defferent 5.6.0'...

'IN' Clause or 'OR'
Hello, [1]: select * from TABLEA where COL1 IN('value1','value2''valu3'....) [2]:select * from TABLEA where COL1 = 'value1' OR COL1= 'value2' OR COL1='valu3'. TABLEA is a huge table and it has non-clustered index on COL1. Among the above 2 queries, which query will give me the better performance or fast response and WHY? What is the difference between 'IN' and 'OR' clauses as for as Sybase Optimization is concerned. Which is the better one to be used on huge tables. Thanks. Mac An IN list is treated ...

'or' or 'union'
Hello I was just wondering, in general what is better to use, an 'or' clause in a select or a 'union' to join two selects together. Do both statements create work tables? Many thanks Alex I think OR will be better than union. because suppose u have 3 tables and using OR u can join table a and table b and table c so each table will have only one read. but using union you will join table a and table b and in another query of union u will use table (a or b) and table c so ur one read is more in union . Ramdas Alex Cheung wrote: > Hello > >...

'To', 'CC', & 'BCC'
Name: Dick Tracy Email: philipdottracyatoptusnetdotcomdotau Product: Thunderbird Summary: 'To', 'CC', & 'BCC' Comments: I have just started using Thunderbird and while I find it quite excellent- I suggest having a button to add addressees to 'BCC' as well. Currently each 'BCC' addressee has to be selected manually. I send e-mail to quite a number of people at a time and I do not wish to readily spread others addresses easily. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0....

EXEC sp_msforeachtable 'sp_spaceused ''?'''
What does the following SQL code mean?  EXEC sp_msforeachtable 'sp_spaceused ''?'''Johan TheunissenMCPD, MCSE, MCTS BizTalk 2006==============================Please mark the most helpful reply/replies as "Answer". JohanNL:sp_msforeachtable This is the name of the SP that resides in the master database.  This SP executes one or more commands for a table. JohanNL:sp_spaceused This is the command that you want to run for each of the tables residing in your current database.  As you might have understood so far, that this is again a...

'Value' should be between 'minimum' and 'maximum'.
I'm attempting to invoke with parameters:  Dim thing2 As New mydelsubPBStep(AddressOf pbStep) Me.Invoke(thing2, "setMax", dt.Rows.Count)      <---- this is where the error occurs   the delegate looks like this: Private Delegate Sub mydelsubPBStep(ByVal mode As String, ByVal value As Integer)   the function it's calling looks like this:Private Sub pbStep(ByVal mode As String, ByVal value As Integer) Select Case mode.ToLower Case "clear" ProgressBar1.Value = 0 Case "step" ProgressBar1.PerformStep() L...

Cannot wrap 'Element''s 'addEventListener' method
On Firefox ( v2 and v3, and probably the earlier versions) it does not seem possible, at least under some circumstances, to extend the 'addEventListener' prototype of the 'Element' object in JS or to extend the prototype of its inheriting objects. This forces JavaScript frameworks that would like to leverage Element's prototype for this (or its inheriting objects) to treat Firefox like IE in this case -- they have to perform an extension operation on every single individual dom element that they need framework-style behavior from. That's a significant performan...

The value's length for key 'data source' exceeds it's limit of '128'.
Hii, When I tried to bind dropdownlist to database by declaring connection string in the code behind file I am getting this error: The value's length for key 'data source' exceeds it's limit of '128'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: The value's length for key 'data source' exceeds it's limit of '128'.Source Error: An...

I'm done with Firefox thanks to 3.0's 'helpfulness'
Name: Eric Weaver Email: weaverepwatyahoodotcom Product: Firefox Summary: I'm done with Firefox thanks to 3.0's 'helpfulness' Comments: I've been an advid Firefox user for a long time. Mosaic, to Netscape, to Firefox. And always with the avoidance of IE (cause I'm forced to use it at work for most things).. I find with Firefox 3.0, after I right this feedback that is, I'm done using your software. The way your address bar tries to be helpful is beyond annoying. I liked the old way, where it started helpfully selecting based on the spelling of what ...

Replace 1's and 0's in a gridview column with Yes's and No's
Is it possible to change the display of a column in a gridview to show a Yes for all 1's and a No for 0's that display in a particular column of a gridview bound to a database?  If so, can someone share the way with me?  I am using ASP.NET 2.0 with VB Code Behind.  Thanks One way you can do is thrrough  CASE in your select statement: Select YesNoColumn= CASE yourColumn WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' ELSE '' END FROM YourtableLimno <Columns>     <asp:TemplateField HeaderText="yourHeader" SortExpression="yourDataField"> ...

It's Linux !? No, it's BSD ! No, no, it's...
kFreeBSD http://wiki.debian.org/Debian_GNU/kFreeBSD a Debian distro using the FreeBSD kernel ! ObiWan wrote: > kFreeBSD > > http://wiki.debian.org/Debian_GNU/kFreeBSD > > a Debian distro using the FreeBSD kernel ! Why use a BSD kernel? I hope the reason is more than, just because they can. http://wiki.debian.org/Debian_GNU/kFreeBSD_why It's easy to understand why the would want to use Debian packages. :) -- Jimmy Johnson Registered Linux User #380263 >> kFreeBSD >> >> http://wiki.debian.org/Debian_GNU/kFreeBSD >> ...

'Help'>'Troubleshooting Information'
Howdy All, 'Help'>'Troubleshooting Information' opens a tab titled "Troubleshooting Information". The "Mail and News Accounts" section is a spreadsheet-like table of INCOMING & OUTGOING account settings. INCOMING has the following column headings: ID, , Name, Connection security, Authentication method OUTGOING has the following column headings: Name, Connection security, Authentication method, Default? For example account4: INCOMING: account4, , (pop3) pop.googlemail.com:995, SSL, passwordCleartext OUTGOING: mail.twc.com:587, alwaysSTARTTLS, passwordCleartext, true In my TBird, there are about 50 accounts listed in the "Mail and News Accounts" table. They are all okay except the following two accounts. account28: INCOMING: account28, , (pop3) pop.googlemail.com:995, SSL, passwordCleartext OUTGOING: mail.twc.com:587, alwaysSTARTTLS, passwordCleartext, true OUTGOING: smtp.gmail.com:587, alwaysSTARTTLS, passwordCleartext, false account59: INCOMING: account59, , (pop3) pop.googlemail.com:995, SSL, passwordCleartext OUTGOING: mail.twc.com:587, alwaysSTARTTLS, passwordCleartext, true OUTGOING: smtp.googlemail.com:465, SSL, passwordCleartext, false Do you see the extra OUTGOING servers in account28 & account59? How can I delete them? Related questions: - How can I discover the real account name of 'account28'? ...

Web resources about - Help 'C' Guru's - grc.techtalk

Resources last updated: 2/18/2016 12:43:20 AM