-
Notifications
You must be signed in to change notification settings - Fork 4
/
Tables.c
63 lines (50 loc) · 1.26 KB
/
Tables.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Tables.c
*
* Sample program to learn to use debugger.
* This program calls function and prints a
* multiplication table. The function returns
* a value that determines if the called function
* succeeded or not.
*/
#include <stdio.h>
#include <stdlib.h>
// Forward declaration for a function that is either
// implemented later in this file or in some other
// source file for which a header file is not included
int PrintTableFor(int);
// We will receive input from user to print table
int main(int argc, char * argv[])
{
int retValue = 0;
// Constants always on left in comparisons!
if(2 != argc){
printf("Usage:\n");
printf("To print table for num, %s <num>\n", argv[0]);
// Always have a single exit point in the function
goto exit;
}
retValue = atoi(argv[1]);
// QQ: What is the value of retValue
// before and after this function call?
retValue = PrintTableFor(retValue);
if(0 != retValue){
printf("PrintTableFor() returned %d\n", retValue);
}
exit:
return 0;
}
int PrintTableFor(int args)
{
int i = 0;
int retValue = 0; // initialized with success
if(0 >= args){
retValue = -1;
goto exit;
}
for(i=1; i<=10; i++){
printf("%d x %2d = %2d\n", args, i, args*i);
}
exit:
return retValue;
}