tutorial c programming language /PDF




tutorial c programming 







Sample of the pdf document 








Exercise 1: Dust Off That Compiler

Here is a simple first program you can make in C:

Source 3: ex1.c
1 int main(int argc, char *argv[])
2 {
3 puts("Hello world.");
4
5 return 0;
6 }


You can put this into a ex1.c then type:
Source 4: Building ex1
1 $ make ex1

cc ex1.c -o ex1
Your computer may use a slightly different command, but the end result
should be a file named ex1 that you can run.


2.1 What You Should See
You can now run the program and see the output.
Source 5: Running ex1

1 $ ./ex1
2
Hello world.
If you don't then go back and fix it.


2.2 How To Break It

In this book I'm going to have a small section for each program on how
to break the program. I'll have you do odd things to the programs, run
them in weird ways, or change code so that you can see crashes and
compiler errors.
For this program, rebuild it with all compiler warnings on:
Source 6: Building ex1 with -Wall
1 $ rm ex1
2 $ CFLAGS="-Wall" make ex1
3
cc -Wall ex1.c -o ex1
4
ex1.c: In function 'main':
5
ex1.c:3: warning: implicit declaration of function 'puts'
6 $ ./ex1
7
Hello world.
8 $
Now you are getting a warning that says the function "puts" is implicitly
declared. The C compiler is smart enough to figure out what you want,
but you should be getting rid of all compiler warnings when you can.
How you do this is add the following line to the top of ex1.c and recompile:
1#include <stdio.h>

Now do the make again like you just did and you'll see the warning go...........








Click here for  Download PDF / FREE

tutorial c programming 



1 commentaire: