Learn to Program With PocketC

back

Contents:

Introduction

Lesson 1 (begin programming)

Lesson 2 (output text to screen)

Lesson 3 (better output)

. .

Introduction

PocketC is a C like langyuage than can be written, compiled, and executed all right on your PDA. A free demo (lasts 60 days) is availbale at Orbworks.

Lesson 1

Most first lessons in programming tutorials begin by saying that one learns to program by programming. Then they proceed to show you to write the code for a program that will output the line "Hello world!" So here we go with the classic "Hello world!". Open memo pad and and make the follow memo:



       //Hello

       main()
       {
	           puts("Hello, world!");
       }

Next you must compile your program (i.e. convert the PocketC source code you created using memo pad into machine language that the PDA can actually execute). Open PocketC and tap on compile. Now you will see the names of any PocketC programs you have written in memo pad. All memos in which the first line begins with the double slashes will appear here. The compiler never tries to compile anything that appears to the right of double slashes on a line. Now highlight "Hello" and tap Compile. If the compiler says you have an error, tap Goto.. and correct any typos. When your program compiles without error click Execute. The program will execute by printing the message "Hello, world!" to the output screen. Of course you may change the program to print whatever you want to the output screen. Everytime you change the program you must compile it again.

Let's take a closer look at the PocketC source code for this program: Just as with C and C++, all work done in PocketC is carried out in functions and every program must have at least a "main" function. Functions are easily identifiable by the parenthesis that immediately follow the function name. Information can be passed to functions by placing it inside the parenthesis. No matter how many functions a program has, execution of the program always begins in the main function and ends in the main function. Curly brackets surround the body of any function for which you yourself are writing the contents. The puts() function has already been written for you (it is in the PocketC function library) so all you have to do is pass information to it. Above we passed a string of characters "Hello world!". The quotation marks identify the phrase as a string of characters. The semicolon at the end of the line tells the compiler when an executable statement has ended.

Lesson 2.

In the "Hello world!" program as written above the program output screen appears so briefly that it is necessary to tap the output button in PocketC to view the output. To solve this problem use the wait() at the end of the "Hello world! program. The modified program should look like this:


          
          #hello

          main()
          {
              puts("Hello world!");
              wait();
          }

Now your program will stop at the program output screen when it finishes executing.

You can decide where your output will appear on the output screen by using the text() function. You need to pass three arguments (i.e. data and info the function needs) to the text()function. The arguments are the position on the screen horizontally, the position on the screen vertically, and the message you want to appear on the screen. The upper lefthand corner of the program output screen is position 0,0 and the lower righthand corner is 150,150. The following code will place the message "Goodbye in the middle of the screen.



          //Goodbye

          main()
          {
               text(55, 75, "Goodbye");
               wait();
          }

To clear the program output screen during the execution of a program use the clear() function.

Lesson 3

You may not like using the program output screen to dispaly your program's output. The graph_on() function will create a screen (without memopad style horizontal lines) just for your programs output.

Pocket C tutorial

PocketC Docs

Hosted by www.Geocities.ws

1