© Fort Street High School Robotics
C is a programming language. We learn it because:
RobotC is a C-based editor and compiler. You'll be able to use most of what you learn in C in RobotC, and there are only some small differences.
Note: We're going to be going to and from C and RobotC. This is mainly so that you learn all the sorts of things standard to coding, that isn't possible with just RobotC. (Also, because we don't have enough licenses for RobotC, as it's not free).
'Hello, World' is the standard way of starting any programming language. Let's see what it is:
// A simple C program!
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
This program is complete - you probably can guess what it does! The key thing is to always read from top to bottom. It has a few things:
Code | Comment |
---|---|
// |
A single line comment. Anything after it on the same line will not be part of your code. |
#include <stdio.h> |
Import the 'standard input/output' library. It supports functions (commands) like 'printf'. |
int main() { ... } |
The main function must appear in every C program. It is the first thing the computer looks for when you run the code. |
printf( ... ) |
A function that lets you print something out to the screen. The 'f' stands for 'formatted'. |
Hello, World!\n |
A string that we want to print out. Anything within double quotes is considered a string. |
\n |
Inserts a new line - makes it pretty. |
return 0 |
0 tells the computer that the program finished without an error. |
We're going to be using an online C compiler - there's many out there but you can use Repl.it. Copy the code above into the left panel of Repl.it.
It should come up with:
Hello, World!
Congratulations, you've written and run your first program!
__
) ( ')
( / )
\(__)|
Make sure the spacing is correct! To print a new line, you need to use the \n
symbol. \
is a special character, so you need to use \\
(e.g. printf("\\");
).