blob: 99c9de1bf85bd36814054c21aa49e1a3daeee229 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
.so re.tmac
.TL
.BI greet ,
an example C program
.AU
John Ankarström
.AB
This is the implementation of
.I greet ,
a simple C program which greets the people
supplied as arguments on the command line.
.AE
.Re greet.c:/^#include/
.LP
First, we include all necessary libraries.
.Re greet.c:/^main(/
.LP
As the program's operation is quite simple,
all its code will be contained in the
.I main
function.
.Re greet.c:/^args:/
.LP
This is where the main operation of the program takes place.
At least one argument is required,
in which case it is simply assigned to the
.I people
string.
If multiple arguments are present,
each is appended to the string in an intelligent way.
At each iteration, it is made certain that the people string
is large enough to contain the new name (and then some).
.Re greet.c:/^concat:/
.LP
If it is the last argument,
the appendix is prefixed with the string " and ".
Otherwise, unless it is the first argument,
it is prefixed with a comma and a space.
Then, the argument is appended to the
.I people
string.
.Re greet.c:/^end:/
.LP
Finally, the people are greeted.
As the program ends here,
there is no need to explicitly free the
.I pepole
string;
the kernel will take care of it for us.
|