Wednesday, May 27, 2009

The story so far.

So far, let's review what I know and what I don't know.

We can write simple loop programs, mainly with integers.  We know that pointers are address for memory.  We can have to program print simple text phrases, of course "hello world."
We do know generally how to read codes in C and the general format of C language.   

What I do not know is writing more complex programs.  How to write to memory or get save files permanently to memory.  How to play complex files like video or audio.   

I must admit, I've started to skim ahead with object-C and also the iphone sdk books.
It only gets harder from here.

Hopefully, our next project will address some of this issue.

Sunday, May 24, 2009

What's the point?

Well, I had to go reread some material.

This is where it gets kinda hard. So stay with me.
Now we have to worry about memory management.  Why do we have to? Well, memory is like everything else, it's finite.  There is only so much to go around.  This leads us to pointers.
Pointers is sort of like a address on the memory.  Think of like it's "pointing" to where in the computer's memory the data is stored.  

There are two conventions in C that denotes pointers
There is the * and &.  Any time you see these two symbols before something, it denotes a pointer.  For example, *myInt and &myInt both means, they are pointers of myInt.
Essentially, myInt = *myInt.  You can manipulate the pointers like you would the actual variable.  

Once you make a pointer, you can place it in code in place of the variable.  Memory in the computer are made up of blocks.  Depends on the type of computer, and the bits, you can have a little or a lot.  But no matter how much memory you have, bad management can lend to poor results.  

This is how I understand pointers.  Not sure if it is entirely correct but I think I got the gist of 
it.

So remember a pointer points to the address of the data in the memory.  That is the take away message from pointers.  I'm told once you start using pointers, you'll use pointers in everything.

We'll see more example of this once we get into coding.


Thursday, May 21, 2009

So on to loops

Now that we have established if and else,

We can concentrate on the while, for, and do.

All of them essentially makes the program go back the the starting step, and will continue to do so until the cycle is broken.  Be careful of infinity loops, that is loops that never breaks.
That means your program will never end, always a bad thing.

The simplest is the while loop.

here is an example code, include the usually int main and all that nice stuff.


{int i;                (interger i)

i = 0;                  (i equals 0)

while (i <3,
1++};                                                                    (increase i by 1)

printf ("finished.\n");                                (print finished when out of loop)

return 0;}                          (stop program)

So there you have it the most basic of loop programming.  The "for" function is about the same as the while function, and I do not know the real basic difference between them.  I do know that for some programs "for" is better than "while" though like I said, I'm not sure why.
The "do" is the same, but the does it's execution at the end of the function instead of the beginning.

Now our program is actually starting to look like a real computer program.  It is running and we can stop it when we want.  You can even play around with the "if" and "else" to control the flow while in the loop.

Next time, we'll try to make a more complicated program.

Sunday, May 17, 2009

Loopy for loops.

Well, so far we have created programs that basically repeat what we say, "hello world."
or a program that can add 3 to 3, together.  Not bad, but these programs are a bit simplistic.
Like all programs the execute their functions the close.  However to make things more interesting, we need to make a program to will continue to run until we tell it to stop.

How do we do that? We do that with loops.
Loops is when the program restarts after completing its' primary function.  It would go back to designated points in the program, like the beginning of the program or function.  

We will investigate a few of these loop functions. 
The ones we'll look at include the "if", "while" and "for" loops.

The "if" function is not really a loop, but I put it in this category since it does direct the flow of the program.  Essentially you are using "if" to state that if something happens the program will do something else.  Like if the football game is on, then I'll watch.  Of course you can make it a bit more complicated.  If the football game is on, then I'll watch, but if it is not then I'll watch something else.   

Let's look at some code to see this in action.

#include stdio.h                         (our rules or parameters)
int main                                      (beginning of our program)

{int myNumber;                        (declaring my variable)
my Number = 1                       (establishing myNumber equals to 1)

if (myNumber == 2)                       (saying if myNumber is equal to 2)
printf ("myNumber is equal to 2");       (then print "myNumber is equal to 2")
else 
printf ("myNumber is not equal to 2");   (or else print "myNumber is not equal to 2")

return 0;}                     (end program)

"if" and "else" introduces the concept of true and false.  The computer will see either the state is true or the statement is false.  By doing this we can direct the program to do what we want by manipulating what happens when the computer encounters the true/false.



Not bad.  Now we can more deeply into loops, if you do not understand it, re do this part again.  It's important.  


I think I'll split this topic into two post, since
1) It is important
2) It's a big subject.


Saturday, May 16, 2009

Hello Operator? Are you there?

What are operators and variables?

Well, after rereading variables and operators, this is how I interpret it.  Variables is the data or the thing that you want to do something with and operators is function that is used.  For example, 1 + 1 = 2,  this is a complete function, 1 is the variable and the + is the operator.  

In C, you are essentially working with variables and how you work with them is the operator.  
Once you learn the terminology the more easier it is to follow.  

There are numerous of operators.  When working with math, the typical operators are all available.  There is +, -, / (divide), * (multiply).   If you see ++, that means plus 1, -- means minus one.  If you see myInt++, that means myInt plus one.  Example myInt = 3, therefore myInt++ = 4.  

Now to get variables to work you must first declare it.  Why do you need to declare it? Well, it is essential to tell the computer here is my data, and I will be working with this data.
For example, int myInt, that tells the computer you will be working with an interger named myInt.  You do this at the beginning of your function.  You can declare multiple variables at once, you just need to separate them by a comma.  For example: int myInt, myNumber.

For example:

#include stido.h  (the rules or sets of premade functions)

int main (always the beginning of our program)

{int myInt; ( declaring the data, myInt will be an integer)

myInt = 3; (stating that myInt equals number 3)

return 0;}  (telling the computer the program is finished)

Not every exciting example, but it shows that by telling the computer that I will be working with  myInt, it will know what to expect in the following code.  Sometimes the computer will even tell you that you have declared something but didn't use it.  That can point to an error where you mistyped a name of your variable or capitalized the wrong letter.

Simple isn't it.  Actually it took a bit for my poor brain the wrap around it.  There are lots of example in the books and the internet that I've read, and this is how I come to understand it.  You can correct me if I'm wrong or have any better examples that you come up with.

Next up:  Loops!!!!!

Thursday, May 14, 2009

Hello World

Okay, so I think I've downloaded everything properly, but there is only one way to find out.
We created a program called hello world. 
(I called mine hello worlda, since this is not my first hello world).



You should see on the top bar, a "run" tab, if you click on it you will get a list of functions. Open the console function.  The console is where all the magic of our programming happens.  This is where you see the fruits of your labor.  

With any luck you see a screen that looks like this.
















Now to test if we had install everything properly, if you click build and go you should see on the console.  (session started)  and the magical "Hello, World!"  Yessss, we did it!!! But wait, that is actually the default program, so you'll always get "Hello, Word!".  We actually just cheated to get our first hello world.  So lets go into the code and see what is happening.  And actually make hello world from scratch. 

On the left hand side you see the project folder with hello world, you'll see the source, documentation, and products.  Well, I can tell you I know next to nothing on most of those.
Click on source and you'll see a file name main.c, that is the meat of our first program.
Below the file name, there is a window, called the editing window.  That is where the code we will write goes.  

the #include form what I gather is like a set of rules for the program you are about to make.   So the computer knows what rules it is going to follow.  I may not be saying this right, but I'll edit this in the future if I can think of a better example.

The next part is the int main.  This is what c programmers called a function.  A function is basically the task that you want the computer to do.  So therefore the int main in this case is the task of writing hello world.  

Now we have to tell the computer how to write hello world and where.  This is were another function printf comes in.  Well, I consider it a function because it is tell the computer to do something.  printf tells the computer that you want to print something on the console.
you printf from int main by brackets.  Programmers love brackets because this keeps the computer for getting confuse.  It is essential in keeping the computer focus and on track.  

To use the printf(). We have to write what to print.  We put what we want to print inside the printf brackets.  We insert what we want to say in between two quotations marks.  The computer knows that anything in quotations will be the actually saying.  

So lets delete all the things after int main, and see if we can get hello world, from scratch.
we'll put curly brackets { printf ( "hello world\n");  return 0;.  why the \n? well that tells the computer to return the cursor to the next line.  You may also wonder why did we put ; at the end of printf?  the ; is actually very important.  From what I read it is like putting a period at the end of a sentence.  If you do not have ; the computer will get confuse very easily.  

Lastly, what is this return 0? (that's return zero, not o.) That is to tell the computer everything is done with printf and return the control back to main.  It's like telling the computer, you've done the task, good job.

With any luck you won't have any nasty syntax errors.  Syntax errors is the computer telling you that your grammar is wrong.  It does not understand what you are trying to say.  Not the end of the world.  Usually I find I might have forgot a ; or a closing bracket somewhere.

YEEESSS, we did it, the console this time reads "hello world"!!.  We wrote a program from scratch and the computer understood us.  I would pat myself on the back if I could, this is actually pretty good for someone with no programming experience.  The first program that all programmers write is done.  

So recap, we learn how to create projects in c, learn that to get the computer to do something you need functions.  Functions are the task that you want to do.  We learn about the printf, the all import ; and return 0.  Not bad, that is the very very basic things in c.


Nex: Onward to variables and operators.  


Let's Get Started

Well, lets start off with the most basic of questions, why do we need to learn a computer language to program a computer?  Well, from what I read so far, a computer only speaks in 1 and 0's..like this 0100101001010101110.  Humans have a really hard time speaking like that, though there are some people who can actually interpret those 1's and 0's.  There for, we need an intermediary, which is where programming language comes in.  The language that you decided to work with will translate what you type or want the computer to do, to those 1's and 0's.  

I'm learning to program on a mac, with the long term goal of making a iphone app.  Therefore I made myself a road map of learning the most basic of language, with is C.  Then we'll move on the object-c, and finally to cocoa touch or iphone SDK.  Why learn C, first when I can go straight to iphone SDK? Well, it's a lot like learning to run, you first have to take the baby steps, and that is what C is.  Once you get a good understanding of C, I'm told you can apply it to multiple languages.  

What is C?  Well, from  what I gather, it is  a standard language develop by some really smart programmers.  Since it is an establish standard, you can program in C on Mac, PC, or any other computer and the computer will understand you.  I will try to write it so that anybody who has no programming experience can follow (like myself).  By showing the steps, hopefully I can understand things better myself.  I always felt you really do not know something unless you are able to teach it to others.  

Since I've read the first book, Learn C on the Mac, I'll tell you what is needed.  Obviously, you need a Mac, but more specifically an Intel Mac if you want to program for the iphone.  I bought an iMac for this purpose only, but you can actually do this on the mac mini or one of the cheaper mac books.  I picked the iMac 24 inch because of the large screen.  The large screen area makes having multiple items open and all on one screen a pretty time saving ability.  Next you need to download from the apple store the iphone SDK.  You can download that for free and it comes with some pretty neat programs.  I elected to sign up for the iPhone Developer program for 99 dollars. Why? Well, it allows me to actually put my program on my iPhone and see how it runs and getting an app into the app store will be our long term goal.  

The iphone SDK comes with the programming tools you'll need to program.  For the Mac the main programming tool you need is Xcode.  Some macs have this preinstall already, so check your mac, to see if you have it.  It should be in your Hard Drive folder under developer.  Then check the applications folder and it should be an icon with a hammer on it with a blue blueprint in the back ground.  For C programming that will be where we'll spend most of our time.

Xcode when you click on it, a screen pops up that says Mac os x resources and Mac Dev Center.  Play around with this since this a great resource for understanding what the programming language can do and it can direct you to answers of questions you may get later on.  You can close that window.  Next your your apple icon on the top left screen when you click on the Xcode, You should see File, edit, view, project, build, run design, scm, window, and help.   I don't know what all of those are use for just yet.  But if you click on File, a window should popup, and you will select new project.  

New Project.  A window pops up will a list of types of programs you want to make. I do not know 99 percent of those.  Hopefully, I will know those someday.  In the Mac os X section, I select command line utility, you should see an icon, called Standard tool.  That is where, You and I will be writing our first codes.   Double click or select that icon and you will see that it brings up a pop-up window and ask you what you want to name this program.  So far everywhere I've read, says you'll start out by writing a small program call "hello world". I elected to keep that name and keep the tradition going.   It will also ask you where do you want to store your program, I elected to keep it in the documents folder.   

So far so good.  We learn how to create a program.  Next step is learning the ins and outs of this first program

Wednesday, May 13, 2009

Day 1. Gathering the resources

I decided to make a blog chronicling my adventures in making an iphone app.  

First: A little background, I have no programming experience what so ever.  I did enroll in a beginning programming course in college but had to drop it due to conflicts with other classes.  I find this task quite daunting, since the programming language is as foreign to me as a language from another country.  My career is in the medical field.  I love my Iphone and love all the applications for it.  I wanted to make an app and put it in the app store, not only for the monetary gains, but mainly I wanted to expand my horizons.  I always wanted to make video games, since that is one of my main hobbies.  Learning to make an iphone app, will be a means to that end.

What I have gather so far.
I suggest those that want to dip their toes into programming, you should check out a website call Tilestack.com.  I program one stack called Mr.Sage.  That was my first programming effort of any kind.  Tilestack lets you play around in a environment that is more friendly to someone who knows nothing of programming.  It takes most of the intimidating coding out of it.  Infact if you make a stack good enough, they would even publish it in the iphone app store.  There are draw backs, since if you publish onto Tilestack there are chance people can steal your idea, as I found out.  And often times what you think is a good stack does not correspond with others, and your stack may not be publish.  But as a start, I find it a great tool to know the basic of programming.

Books:  I bought these books since I did a quick google search, and they seem to be the most recommended.

1)Learn C on the MAC by Dave Mark, publish by Apress
I find this book pretty easy to understand and it was written with people who have no experience in mind.  I have read this book through and was able to accomplish so of the simple programming.  The book becomes harder to read about half way through, but stick with it.  I had to reread it several times already.

2)Learn Objective-C on the Mac by Mark Dalrymple / Scott Knaster, publish by Apress
I only started to read this book, since it just came in the mail from amazon.
So far, some of the the things, I learned from the first book, carries over to this, but it is a bit more difficult to follow.  Probably will have to take it slow....really slow.

3)Beginning iPhone Development: Exploring the iPhone SDK by Dave Mark/ Jeff LaMarche, publish by APress.  
I have read only the first two chapters, from what I know this will probably be difficult to follow if I do not understand objective-c (which I don't yet).  This seems quite a bit different from C language, but we'll know more once I go through the book in more detail. 

WebSites:
So far the best website I found is iPhone development Central.  They have video tutorials, though I find most of them difficult to follow from a non programmer perspective.  I decided to join their forums since they appear to be a community of programmers from different level of expertise.  Some of the members are friendly and would gladly give a helping hand to newbies. 

Another great website is called Masters of the Void.  This is essentially learning C, but in a more truncated form.  If you do not want to buy the book, this would be the first step I recommend.  

Well, That's it for now, back to reading and programming.