So the basic structure of C is like BASIC, with logic arguments and loops and stuff. What is the difference? Why is C so different? :/
It's not, really. Almost everything you learned about creating programs from an idea in TI-BASIC applies more or less directly to C programming. There's more complexity to worry about, like scoped variables, functions with arguments, structures, and pointers, but it's easy as long as you don't do something silly like try beginner programming projects in C that are well beyond how far you've learned, or try to learn without doing.
Although it is essentially an argument about which is better, it is very educational about the differences
http://forums.xkcd.com/viewtopic.php?t=37904#p1506245
Thanks Kerm, that makes me feel better about it! I will definitely learn by doing, which is what i did with BASIC ;D
What kind of program should i try and make first? Like what kind would be good for hands on learning?
Pong, a Maze game. Maybe a program that uses all the different functions of Mateo's library depending on what key you press. That might be a little harder...
Something you can do is make a copy of a game that you've made in TI-BASIC. That way, you already know game mechanics, and it better helps you understand how C is different.
Pieman7373 wrote:
What kind of program should i try and make first? Like what kind would be good for hands on learning?


AS calcnerd said, try something you've already made in TI-BASIC, or even just start with moving a sprite around the screen and going from there!
Okay! Thanks both of you! (calcnerd and unicorn)
the biggest changes to take note of when moving from basic to c are:

1-a. proper functions!!!
1-b. the concept of scope
2. the split between stack and heap memory
3. the more-extensive, and extensible, type system
4. lower-level functionality, like bit-wise ops and inline asm

less obvious, but of equal importance, are things like arbitrary variable names and better support for splitting a program over several files.

together, these features allow for writing much more maintainable programs. because of its greater flexibility, however, one could easily ignore all this functionality and write programs nearly identical to their BASIC counterparts (i.e. a densely-packed wall of spaghetti). thus, it's well worth researching these topics and trying to stick to a clean, readable style before old habits take over and improving becomes more difficult. good luck!

also, in reference to which thing you should try first: make sure it's something you're actually interested in!
I whipped up this BASIC program yesterday specifically to covert it to C. Does it look fine?



Code:

Lbl 00
ClrDraw
AxesOff
ZStandard
ZDecimal
ZSquare
Horizontal 4.1,Black
Horizontal -4.05,Black
Vertical -6.6,Black
Vertical 9.55,Black
0->A
While A<150
   randInt(3,160)->X
   randInt(3,260)->Y
   Pxl-On(X,Y,Red):Pxl-On(X+1,Y,Red):Pxl-On(X,Y+1,Red):Pxl-On(X+1,Y+1,Red):Pxl-On(X+2,Y,Red):Pxl-On(X+2,Y+1,Red):Pxl-On(X+2,Y+2,Red):Pxl-On(X,Y+2,Red):Pxl-On(X+1,Y+2,Red)
   A+1->A
End
randInt(3,160)->C
randInt(3,260)->D
Pxl-On(X,Y,Green):Pxl-On(X+1,Y,Green):Pxl-On(X,Y+1,Green):Pxl-On(X+1,Y+1,Green)
2->X:2->Y
Lbl 01
getKey ->K
If K=45:Stop
Pxl-On(X,Y,Gray):Pxl-On(X+1,Y,Gray):Pxl-On(X+1,Y,Gray):Pxl-On(X+1,Y+1,Gray)
If K:Then
   Pxl-Off(X,Y):Pxl-Off(X+1,Y):Pxl-Off(X,Y+1):Pxl-Off(X+1,Y+1)
   Y+(((K=26)*4)+((K=24)*-4))->Y
   X+(((K=34)*4)+((K=25)*-4))->X
   If Y<2:261->Y
   If Y>261:2->Y
   If X<2:161->X
   If X>161:2->X
   0->B
   If pxl-Test(X,Y):1->B
   If pxl-Test(X+1,Y):1->B
   If pxl-Test(X,Y+1):1->B
   If pxl-Test(X+1,Y+1):->B
   If B=1:Goto 02
   Goto 01
End
Goto 01
Lbl 02
If X=C and Y=D
Then
   TextColor( Green
   Text(-1,65,65,"You Win!!!!!"
   Goto 03
End
TextColor(Red
Text(-1,65,65,"You Died!!!!"
Lbl 03
getKey ->K
If K=45:Stop
If K=105:Goto 00
Goto 03

That looks pretty nice indeed, and should be pretty easy to convert to C. Also note that the toolchain already has a randInt(low, high) definition as well to make it even easier Smile
I went over your program and found a few things...

Code:
   If pxl-Test(X+1,Y+1):->B

found a typo...

ZStandard
ZDecimal
ZSquare

watt?

Lbl 03
getKey ->K
If K=45:Stop
If K=105:Goto 00
Goto 03

This is not a problem, but why do you use a label for this rather than a regualar loop?
I meant to say 1->

I say zstandard to undo any window changes, and then do the other two zooms to make the coordinates for pt-on easier. But I think I got rid of all of the points in the program ;

I use a Lbl because 2 different things use it...

The typo doesn't exist on my calculator (where I made the program)
In TI-Basic, you would use labels to call something that's always called, while in C, you just make a separate function. Make sure you do it that way. Goto and labels in C are shunned against by many C programmers except when you want to get out of many nested loops or switch's when a break won't suffice.
Just a pointer. (Get it!?)
So in C, you would just put the function separately, and then use a pointer? are pointers kinda like Goto?
Pieman7373 wrote:
So in C, you would just put the function separately, and then use a pointer? are pointers kinda like Goto?

No. Sorry. That pointer thing was a joke. My fault for not making it obvious. Say your labeled section in Basic is called foo(); in C. In the main function, you would just call foo(); when you want the code in function foo to execute.
so the function is like a stored variable that gets recalled whenever i want? The code just borrows it to use it? like a library book!
Sort of?

you do this below your main program that runs first.:


Code:
void myFunctionName(void) {
Display things
math things
}

and you call it in your main program part and it runs the code you put between the brackets above. It is just a way to name things that happen for readability, and to lower the size of your code if you run those commands multiple times.

Code:
myFunctionName();

and then you declare it by your globals:

Code:
void myFunctionName(void);


And about the Goto thing, you are using it to loop, instead, put Lbl 3 and then create a loop underneath that so you don use gotos as a loop, which is much slower, I believe. So:


Code:
Lbl 3
Repeat K=45
getkey->K
//and so on
End

If you don have a Goto 3 somewhere else in the program, just remove the Lbl altogether. Wink
Thank You!! This was very much helpful! I will fix that in my code!

Edit#2, fixed some other stuff, i think)
I fixed the code i think:

Code:

Lbl 00
ClrDraw
AxesOff
ZStandard
ZDecimal
ZSquare
Horizontal 4.1,Black
Horizontal -4.05,Black
Vertical -6.6,Black
Vertical 9.55,Black
0->A
While A<150
   randInt(3,160)->X
   randInt(3,260)->Y
   Pxl-On(X,Y,Red):Pxl-On(X+1,Y,Red):Pxl-On(X,Y+1,Red):Pxl-On(X+1,Y+1,Red):Pxl-On(X+2,Y,Red):Pxl-On(X+2,Y+1,Red):Pxl-On(X+2,Y+2,Red):Pxl-On(X,Y+2,Red):Pxl-On(X+1,Y+2,Red)
   A+1->A
End
randInt(3,160)->C
randInt(3,260)->D
Pxl-On(X,Y,Green):Pxl-On(X+1,Y,Green):Pxl-On(X,Y+1,Green):Pxl-On(X+1,Y+1,Green)
2->X:2->Y
Lbl 01
getKey ->K
If K=45:Stop
Pxl-On(X,Y,Gray):Pxl-On(X+1,Y,Gray):Pxl-On(X+1,Y,Gray):Pxl-On(X+1,Y+1,Gray)
If K:Then
   Pxl-Off(X,Y):Pxl-Off(X+1,Y):Pxl-Off(X,Y+1):Pxl-Off(X+1,Y+1)
   Y+(((K=26)*4)+((K=24)*-4))->Y
   X+(((K=34)*4)+((K=25)*-4))->X
   If Y<2:261->Y
   If Y>261:2->Y
   If X<2:161->X
   If X>161:2->X
   If X=C and Y=D:Goto 02
   0->B
   If pxl-Test(X,Y):1->B
   If pxl-Test(X+1,Y):1->B
   If pxl-Test(X,Y+1):1->B
   If pxl-Test(X+1,Y+1):1->B
   If B=1:Goto 02
   Goto 01
End
Goto 01
Lbl 02
If X=C and Y=D
Then
   TextColor( Green
   Text(-1,65,65,"You Win!!!!!"
Else 
   TextColor(Red
   Text(-1,65,65,"You Died!!!!"
End   
0->E
Repeat E=1
   getKey ->K
   If K=45 or K=105:1->E
   If K=45:Stop
   If K=105:Goto 00
End


But,SourceCoder says:

Code:
Error on line 52 at "...   <br />0->E<br />Repeat E=...".<br />

and i dont know why...

Fixed that, and got rid of E, which i didn't really need

Code:
Lbl 00
ClrDraw
AxesOff
ZStandard
ZDecimal
ZSquare
Horizontal 4.1,Black
Horizontal -4.05,Black
Vertical -6.6,Black
Vertical 9.55,Black
0->A
While A<150
   randInt(3,160)->X
   randInt(3,260)->Y
   Pxl-On(X,Y,Red):Pxl-On(X+1,Y,Red):Pxl-On(X,Y+1,Red):Pxl-On(X+1,Y+1,Red):Pxl-On(X+2,Y,Red):Pxl-On(X+2,Y+1,Red):Pxl-On(X+2,Y+2,Red):Pxl-On(X,Y+2,Red):Pxl-On(X+1,Y+2,Red)
   A+1->A
End
randInt(3,160)->C
randInt(3,260)->D
Pxl-On(X,Y,Green):Pxl-On(X+1,Y,Green):Pxl-On(X,Y+1,Green):Pxl-On(X+1,Y+1,Green)
2->X:2->Y
Lbl 01
getKey ->K
If K=45:Stop
Pxl-On(X,Y,Gray):Pxl-On(X+1,Y,Gray):Pxl-On(X+1,Y,Gray):Pxl-On(X+1,Y+1,Gray)
If K:Then
   Pxl-Off(X,Y):Pxl-Off(X+1,Y):Pxl-Off(X,Y+1):Pxl-Off(X+1,Y+1)
   Y+(((K=26)*4)+((K=24)*-4))->Y
   X+(((K=34)*4)+((K=25)*-4))->X
   If Y<2:261->Y
   If Y>261:2->Y
   If X<2:161->X
   If X>161:2->X
   If X=C and Y=D:Goto 02
   0->B
   If pxl-Test(X,Y):1->B
   If pxl-Test(X+1,Y):1->B
   If pxl-Test(X,Y+1):1->B
   If pxl-Test(X+1,Y+1):1->B
   If B=1:Goto 02
   Goto 01
End
Goto 01
Lbl 02
If X=C and Y=D
Then
   TextColor( Green
   Text(-1,65,65,"You Win!!!!!"
Else 
   TextColor(Red
   Text(-1,65,65,"You Died!!!!"
End
Repeat K=45 or K=105
   getKey ->K
   If K=45:Stop
   If K=105:Goto 00
End


Edit: I got rid of the return

Code:
Lbl 00
ClrDraw
AxesOff
ZStandard
ZDecimal
ZSquare
Horizontal 4.1,Black
Horizontal -4.05,Black
Vertical -6.6,Black
Vertical 9.55,Black
0->A
While A<150
   randInt(3,160)->X
   randInt(3,260)->Y
   Pxl-On(X,Y,Red):Pxl-On(X+1,Y,Red):Pxl-On(X,Y+1,Red):Pxl-On(X+1,Y+1,Red):Pxl-On(X+2,Y,Red):Pxl-On(X+2,Y+1,Red):Pxl-On(X+2,Y+2,Red):Pxl-On(X,Y+2,Red):Pxl-On(X+1,Y+2,Red)
   A+1->A
End
randInt(3,160)->C
randInt(3,260)->D
Pxl-On(X,Y,Green):Pxl-On(X+1,Y,Green):Pxl-On(X,Y+1,Green):Pxl-On(X+1,Y+1,Green)
2->X:2->Y
Lbl 01
getKey ->K
If K=45:Stop
Pxl-On(X,Y,Gray):Pxl-On(X+1,Y,Gray):Pxl-On(X+1,Y,Gray):Pxl-On(X+1,Y+1,Gray)
If K:Then
   Pxl-Off(X,Y):Pxl-Off(X+1,Y):Pxl-Off(X,Y+1):Pxl-Off(X+1,Y+1)
   Y+(((K=26)*4)+((K=24)*-4))->Y
   X+(((K=34)*4)+((K=25)*-4))->X
   If Y<2:261->Y
   If Y>261:2->Y
   If X<2:161->X
   If X>161:2->X
   If X=C and Y=D:Goto 02
   0->B
   If pxl-Test(X,Y):1->B
   If pxl-Test(X+1,Y):1->B
   If pxl-Test(X,Y+1):1->B
   If pxl-Test(X+1,Y+1):1->B
   If B=1:Goto 02
   Goto 01
End
Goto 01
Lbl 02
If X=C and Y=D
Then
   TextColor( Green
   Text(-1,65,65,"You Win!!!!!"
Else 
   TextColor(Red
   Text(-1,65,65,"You Died!!!!"
End
While 1
   getKey ->K
   If K=45:Stop
   If K=105:Goto 00
End




Now I just need to start trying to convert this to C ;P
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement