For now, it's not important that you understand all those cryptic C commands. All that matters is that minutes from now, you will have learnt how to create a program in C, compile it and run it. Then you can act all smug in front of your mates ;)
- 1 -
At the command line, pick a directory to save you program and enter:
pico firstprog.cNote
All C source code files MUST have a '.c' file extension.
- 2 -
Enter the following program:
#include <stdio.h> int main() { int index; for (index = 0; index < 7; index = index + 1) printf ("Hello World!\n"); return 0; }- 3 -
Save and exit Pico.
- 4 -
Enter:
gcc -o myprog firstprog.c...to create an executable from your source code ('firstprog.c').
Here's a detailed discussion of the line above:
- 'gcc' (GNU C Compiler) is passed...
- ...'-o' which means give the executable the name that follows (i.e. 'myprog').
- ...and the program to compile (referred to as 'source code') is 'firstprog.c'.
- 5 -
To run this example program, enter:
./myprogThe './' means run a file located in the current directory. You could quite easily have entered something like:
/home/Laurence/myprog...If '/home/Laurence' happened to be the directory 'myprog' was in.
Link
By Laurence Hunter laurence@thebits.co.uk
www.THEBITS.co.uk - updated daily...