First Program in C
Now that I’ve got Ruby and Rails fairly well learned and practiced, I decided it was time to start working towards my long term goal of blending my programming skills with my love of art. Here is my first baby step towards learning C:
touch foo.c
mate foo.c
In foo.c I wrote (with the help of my roommate Sean):
`#include <stdio.h> int main() {
int i;
printf("Hello World!!!!!!\n");
for(i=0; i<5; i++) {
printf("%d\n", i);
}
return 0;
}`
Next, I compiled my program:
gcc foo.c
This created a file called a.out
Next I ran a.out
./a.out
And it out put:
Hello World!!!!!!
0
1
2
3
4
Sean also taught me how to define the name of the out file:
gcc -o foo foo.c
This let me do the following to execute my program:
./foo
Posted by Liah on Monday, October 04, 2010