User:Yiorgos Bagakis/prototyping/assignment3

From XPUB & Lens-Based wiki

C programming practice

The following baby programs were written using the Gedit text editor. The idea was to familiarize myself with C before using it with Arduino. So first attempt was to recreate the clapping music that we did with Micheal as the 2nd prototyping assigment but most of us didn't really complete it successfully.

file: loop.c

description: a simple while loop printing "hello world" 6 times.

#include "stdio.h"

int i=65;


int main () //it's an integer variable but is actually a function - it is standard for every C program 
    {
    i=1;
    while (i<63)
    	{
	printf("hello world %d\n", i); //whatever i get here (i) paste it here (%d\n) and is a decimal (d)
    	//printf("hello world %c\n", i); //whatever i get here (i) paste it here (%c\n) and is a char (c)
        i = i * 2;
	}
    }

//gcc loop.c -o loop
//$ ./loop
// the above 2 lines are for running the loop.c on the terminal...
//for ASCII check the tables eg on google. in our case: A=65
//printf function expects a string inside...eg: "hello world"
//debugging tip! Use printf (for C) or Serial.printf (for Arduino)- to test if things work
//
//to compile use this:
//gcc -g loop.c -o loop
//ddd loop
//ddd is a gnu compiler - download it first :)