1 /*
2  *  example.c
3  *
4  *  Calculate the sum of a given range of integer numbers. The range is
5  *  specified by providing two integer numbers as command line argument.
6  *  If no arguments are specified, assume the predefined range [0..9].
7  *  Abort with an error message if the resulting number is too big to be
8  *  stored as int variable.
9  *
10  *  This program example is similar to the one found in the GCOV documentation.
11  *  It is used to demonstrate the HTML output generated by LCOV.
12  *
13  *  The program is split into 3 modules to better demonstrate the 'directory
14  *  overview' function. There are also a lot of bloated comments inserted to
15  *  artificially increase the source code size so that the 'source code
16  *  overview' function makes at least a minimum of sense.
17  *
18  */
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include "iterate.h"
23 #include "gauss.h"
24 
25 static int start = 0;
26 static int end = 9;
27 
28 
main(int argc,char * argv[])29 int main (int argc, char* argv[])
30 {
31 	int total1, total2;
32 
33 	/* Accept a pair of numbers as command line arguments. */
34 
35 	if (argc == 3)
36 	{
37 		start	= atoi(argv[1]);
38 		end	= atoi(argv[2]);
39 	}
40 
41 
42 	/* Use both methods to calculate the result. */
43 
44 	total1 = iterate_get_sum (start, end);
45 	total2 = gauss_get_sum (start, end);
46 
47 
48 	/* Make sure both results are the same. */
49 
50 	if (total1 != total2)
51 	{
52 		printf ("Failure (%d != %d)!\n", total1, total2);
53 	}
54 	else
55 	{
56 		printf ("Success, sum[%d..%d] = %d\n", start, end, total1);
57 	}
58 
59 	return 0;
60 }
61