Thursday, October 8, 2015

Getting Started


What can I do with Raspberry PI? 


I can learn how to program it.


Let’s begin then.



Information Gathering

Each program is made of functions and variables. Code must be compiled to produce executable file.


Reflection

Functions
A function contains statements which end with semicolon ; . Statement specify what need to be done. Function main() has a special meaning as it marks where the program should start its execution. Data (variables) can be provided to the function inside the parentheses (). They are called arguments. I already know that functions can manipulate data (arguments) and return data as well. The returned data can be used by other functions. The braces {} will contain block of instructions.


Variables
Variables store values that will be used during computation.


Compilation and Linking
It is a process of converting the source code into code that the processor can understand and execute.


Functions
A function contains statements which end with semicolon . Statement specify what need to be done. Function main() has a special meaning as it marks where the program should start its execution. Data (variables) can be provided to the function inside the parentheses (). They are called arguments. I already know that functions can manipulate data (arguments) and return data as well. The returned data can be used by other functions. The braces {} will contain block of instructions.


Variables
Variables store values that will be used during computation.


Compilation and Linking
It is a process of converting the source code into code that the processor can understand and execute.

Creation

Based on the first reading I recreated the program.

hello.c


 #include <stdio.h>   
     
  int main() {   
     
   printf("Hello World!\n");   
     
   return 0;   
  }  


#include

During the compilation process the content of the file 'stdio.h', which c compiler knows how to locate, will be included with the source code. This particular file is called standard library which allows my program to use function printf() that will display the string 'Hello World' on the screen.

int main() {

Function main() which starts execution of each C program will take no arguments as the parentheses are empty. The left brace will mark where the block of statements will go.

printf("Hello World!\n");

Function printf() is part of standard library that displays the argument (here string 'Hello World!') on the screen. The special character \n will add new line after the string. The backslash \ is so called escape sequence informing the program that what follows has a special meaning. For instance \n is new line, \t is tabulator. Each C statement must end with semicolon ; which is mandatory. Otherwise it will contain errors and will not compile.

return 0;

This statement will return code '0' to the operating system that started execution of the program. The code '0' means that the program ended without any problem.

}

Closing brace ends the block of code in the function main().
Compilation of this program to produce an executable file in Raspberry PI:

 gcc -o hello hello.c  

Running code:
 ./hello  

Testing

Exercise 1-1.
Run the 'hello, world' program on your system. Experiment with leaving out parts of the program, to see what error messages you get.

Error 1

 #include <stdio.h   
     
  int main() {   
     
   printf("Hello World!\n");   
     
   return 0;   
  }  

Result while compiling:


 jaro@eurisko ~/code/c/orangeAcademy $ gcc -o hello hello.c    
  hello.c:1:18: error: missing terminating > character   
  jaro@eurisko ~/code/c/orangeAcademy $  

Error 2


 #include <stdio.h>   
     
  int main( {   
     
   printf("Hello World!\n");   
     
   return 0;   
  }  

Results while compiling:
 jaro@eurisko ~/code/c/orangeAcademy $ gcc -o hello hello.c    
 hello.c:3:11: error: expected declaration specifiers or ‘...’ before ‘{’ token   
 jaro@eurisko ~/code/c/orangeAcademy $  

Error 3 
 #include <stdio.h>   
     
  int main() {   
     
   printf("Hello World!\n);   
     
   return 0;   
  }  
Results while compiling:


 jaro@eurisko ~/code/c/orangeAcademy $ gcc -o hello hello.c    
 hello.c: In function ‘main’:   
 hello.c:5:12: warning: missing terminating " character [enabled by default]   
 hello.c:5:5: error: missing terminating " character   
 hello.c:7:5: error: expected expression before ‘return’   
 hello.c:8:1: error: expected ‘;’ before ‘}’ token   
 jaro@eurisko ~/code/c/orangeAcademy $  

Error 4


 #include <stdio.h>   
     
  int main() {   
     
   printf("Hello World!\n")   
     
   return 0;   
  }  

Results while compiling:
 jaro@eurisko ~/code/c/orangeAcademy $ gcc -o hello hello.c   
 hello.c: In function ‘main’:   
 hello.c:7:5: error: expected ‘;’ before ‘return’   
 jaro@eurisko ~/code/c/orangeAcademy $  

Exercise 1-2.
Experiment to find out what happens when prints 's argument string contains \c, where c is some character not listed above.



 #include <stdio.h>   
     
  int main() {   
     
   printf("Hello World!\h");   
     
   return 0;   
  }  

Results while compiling:
 jaro@eurisko ~/code/c/orangeAcademy $ gcc -o hello hello.c   
 hello.c: In function ‘main’:   
 hello.c:5:12: warning: unknown escape sequence: '\h' [enabled by default]   
 jaro@eurisko ~/code/c/orangeAcademy $  

Cisco Is Easy - Main

  Cisco Basics (CCNA level)  Lessons: Watch Video Tutorials on Youtube 01 - Connecting to Cisco Console Port with MINICOM 02 - Navigatin...