RE: A89: Re: Please help with C


[Prev][Next][Index][Thread]

RE: A89: Re: Please help with C




Hey thanks a ton but I am still getting an error, I  changed my code and put
it below. I am getting a parse error with the line that loads the buffer.
I also tried using the labeling and goto like you said but I got a ton of
error from everything inside that label. I did..  main2:
I don't know if that is what you meant but that is how it is done in Java (I
think if I remember right.) so I assumed so.
Well thanks again for putting up with my not knowing C.


//My code, yet again
#include <doors.h>
#include <graph.h>
#include <kbd.h>

int _ti89,_ti92plus;      // compile for both calcs
int font;
int kbkey;
void _main(void)
{
  LCD_BUFFER buffer;
  LCD_save(buffer);
  font = 2;
  FontSetSys(F_6x8);
}
int main2(void)
{ 
  ClrScr();
  DrawStr(3,3,"Move Me",A_NORMAL);
  kbkey = ngetchx();
  if(kbkey == 43)
  { if(font == 2)
    { font += 1;
      FontSetSys(F_8x10);
	}
	if(font == 1)
	{ font += 1;
      FontSetSys(F_6x8);
    }  
  }
  if(kbkey == 45)
  { if(font == 2)
    { font -= 1;
      FontSetSys(F_4x6);
    }
	  if(font == 3)
    { font -= 1;
      FontSetSys(F_6x8);
    }
  }
  if(kbkey != 264)
  { main2();
  }
 }
int emd(void)
{ LCD_restore(buffer);
}







-----Original Message-----
From: owner-assembly-89@lists.ticalc.org
[mailto:owner-assembly-89@lists.ticalc.org]On Behalf Of Zeljko Juric
Sent: Tuesday, April 04, 2000 12:36 AM
To: assembly-89@lists.ticalc.org
Subject: A89: Re: Please help with C



Hi!

> Below is my source. I can not figure out why it wont compile. It is
> something with loading the variable "buffer" to restore the screen at the
> end of the program. 

First, you cannot start a new function inside of another function. You
start definition of "main2" before end of definition of "_main". This is
the main problem in your program. I have not enough time at the moment
to elaborate it in more details. I am hope that I am not the only person
who knows C, so somebody else will give additional info to you. If you
still can't solve the problem, mail again, and I will give to you more
detailed answer a bit later (maybe tommorow)...

Anyway, your program has a bad structure. "main2" calls "loop" and
"loop" calls "main2". Such mutual recursion is not a good idea (expect
when it is really necessary, for example in programing of logic games).
And, why statements like

if(font == 1)
 { 
 }

e.g. if font==1 then do nothing? Simply remove these statements and
the program will "do nothing" :-)

> I don't think I am understanding the jumping and labeling part of C.
> I haven't read anything on it this is just what I have learned from 
> looking at others source code.

Can you be more concrete: what do you want to know exactly? I will only
tell to you: if you want unconditional jumps, the simplest way to do so
is "goto", like in:

label:    // the colon ":" ends a label
...
goto label;

with the limitation that "goto" can not jump from one function to 
another, and you can't jump into a middle of a compound statement.
But, note that "goto" is "damned" in C: you need not to use "goto".
It can be avoided using "for", "while", "do".."while", "break" and
"continue" statements. Look some books about C.

> I also have another question how do you do "or" or "and" in a conditional
> statement like.....
> if varibleA = VariableB and VariableC - VariableA
> {.....
> }

"&&" is "and", and "||" is "or". But, "=" is assigning, not a comparation.
Comparation is "==". So, you need to do

if (varibleA == VariableB && VariableC == VariableA)
  {.....
  }


> Thanks for the help.
> 
> 
> //my code
> #include <doors.h>
> #include <graph.h>
> #include <kbd.h>
> 
> int _ti89,_ti92plus;      // compile for both calcs
> int font;
> int kbkey;
> void _main(void)
> {
>   LCD_BUFFER buffer;
>   LCD_save(buffer);
>   font = 2;
>   FontSetSys(F_6x8);
> 
> int main2(void)
> { 
>   ClrScr();
>   DrawStr(3,3,"Move Me",A_NORMAL);
>   loop();
> }
> int loop(void)
> {
>  kbkey = ngetchx();
>  if(kb
key == 43)
>   { if(font == 2)
>     { font += 1;
>       FontSetSys(F_8x10);
> 	}
>     if(font == 3)
> 	{
>     }
> 	if(font == 1)
> 	{ font += 1;
>       FontSetSys(F_6x8);
>     }
>   }
>   if(kbkey == 45)
>   { if(font == 2)
>     { font -= 1;
>       FontSetSys(F_4x6);
>     }
> 	  if(font == 1)
>

>     }
> 	  if(font == 3)
>     { font -= 1;
>       FontSetSys(F_6x8);
>     }
>   }
>  if(kbkey != 264)
>   { main2();
>   }
>  }
>  LCD_restore(buffer);
> }
>
>
> __________________________________________________
> Do You Yahoo!?
> Talk to your friends online with Yahoo! Messenger.
> http://im.yahoo.com


__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com



Follow-Ups: References: