programming:c:hello_world
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
programming:c:hello_world [2013/08/05 15:26] – zufd | programming:c:hello_world [2014/12/11 16:22] (current) – czuber | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Hello world ! ====== | ====== Hello world ! ====== | ||
- | ===== Exercice 1 ===== | + | ===== Exercice 1 : printf |
* Open a terminal | * Open a terminal | ||
Line 26: | Line 26: | ||
</ | </ | ||
* Then run your programm by typing " | * Then run your programm by typing " | ||
+ | |||
+ | |||
+ | |||
+ | ===== Exercice 2 ===== | ||
+ | |||
+ | * Open a terminal | ||
+ | * Copy the content of the first exercice to the second by writing the following command | ||
+ | < | ||
+ | cp ex1.c ex2.c | ||
+ | </ | ||
+ | * Open ex2.c with vim | ||
+ | < | ||
+ | vim ex2.c | ||
+ | </ | ||
+ | * Edit your file so it looks like this : | ||
+ | <code c> | ||
+ | #include < | ||
+ | |||
+ | int main(){ | ||
+ | #ifdef DEBUG | ||
+ | printf(" | ||
+ | #endif | ||
+ | |||
+ | return 0 ; | ||
+ | } | ||
+ | </ | ||
+ | * Compile your code with gcc | ||
+ | < | ||
+ | gcc -Wall ex2.c -o ex2 | ||
+ | </ | ||
+ | * Run it with " | ||
+ | * Nothing should happen, it's normal because you didn't tell the compiler to use preprocessor parts. Which are defined by the #ifdef #endif quotes | ||
+ | * now recompile your program with the following line | ||
+ | < | ||
+ | gcc -Wall -DDEBUG ex2.c -o ex2 | ||
+ | </ | ||
+ | * Run it again | ||
+ | * Hello world ! | ||
+ | ===== Exercice 3 : scanf ===== | ||
+ | |||
+ | * Open a terminal | ||
+ | * Create your file by writing the following command | ||
+ | <code c> | ||
+ | vim ex3.c | ||
+ | </ | ||
+ | * Enter insertion mode by pressing Insert | ||
+ | * Write the lines below | ||
+ | <code c> | ||
+ | # | ||
+ | |||
+ | int main(int argc, char** argv) | ||
+ | { | ||
+ | char nom[14]; | ||
+ | printf(" | ||
+ | scanf(" | ||
+ | printf(" | ||
+ | | ||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | * Then press Esc key | ||
+ | * Write :wq | ||
+ | * Compile your code with the following line | ||
+ | < | ||
+ | gcc -Wall ex3.c -o ex3 | ||
+ | </ | ||
+ | * Then run your programm by typing " | ||
+ | ===== Exercice 4 : for ===== | ||
+ | |||
+ | * Open a terminal | ||
+ | * Create your file by writing the following command | ||
+ | <code c> | ||
+ | vim ex4.c | ||
+ | </ | ||
+ | * Enter insertion mode by pressing Insert | ||
+ | * Write the lines below | ||
+ | <code c> | ||
+ | # | ||
+ | |||
+ | int main(int argc, char** argv) | ||
+ | { | ||
+ | int nbrMax; | ||
+ | int i = 1; | ||
+ | printf(" | ||
+ | scanf(" | ||
+ | printf(" | ||
+ | for(i=1; | ||
+ | { | ||
+ | printf(" | ||
+ | } | ||
+ | | ||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | * Then press Esc key | ||
+ | * Write :wq | ||
+ | * Compile your code with the following line | ||
+ | < | ||
+ | gcc -Wall ex4.c -o ex4 | ||
+ | </ | ||
+ | * Then run your programm by typing " | ||
+ | ===== Exercice 5 : for in for ===== | ||
+ | |||
+ | * Open a terminal | ||
+ | * Create your file by writing the following command | ||
+ | <code c> | ||
+ | vim ex5.c | ||
+ | </ | ||
+ | * Enter insertion mode by pressing Insert | ||
+ | * Write the lines below | ||
+ | <code c> | ||
+ | # | ||
+ | |||
+ | int main(int argc, char** argv) | ||
+ | { | ||
+ | int i = 1; | ||
+ | int j = 1; | ||
+ | int nbrMax = 10; | ||
+ | for(i=1; | ||
+ | { | ||
+ | for(j=1; | ||
+ | { | ||
+ | printf(" | ||
+ | } | ||
+ | printf(" | ||
+ | } | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | * Then press Esc key | ||
+ | * Write :wq | ||
+ | * Compile your code with the following line | ||
+ | < | ||
+ | gcc -Wall ex5.c -o ex5 | ||
+ | </ | ||
+ | * Then run your programm by typing " |
programming/c/hello_world.1375716418.txt.gz · Last modified: 2013/08/05 15:26 by zufd