-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaddargs.c
More file actions
executable file
·60 lines (38 loc) · 756 Bytes
/
addargs.c
File metadata and controls
executable file
·60 lines (38 loc) · 756 Bytes
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
#include <stdio.h>
int error ;
int convert(char *q)
{
int i,v ;
error = 0 ;
i = v = 0 ;
while (q[i] != '\0') {
if ((q[i] >= '0') && (q[i] <= '9')) {
v = v*10 + (q[i] - '0') ;
}
else {
error = 1 ; return 0 ;
}
i++ ;
}
return v ;
}
int main (int argc, char **argv)
{
int a,b,c ;
if (argc != 3) {
printf("usage :pgm_name unsigned_integer1 unsigned_integer2\n") ;
exit(1) ;
}
a = convert(argv[1]) ;
if (error) {
printf("%s is not an unsigned integer\n", argv[1]) ;
exit(1) ;
}
b = convert(argv[2]) ;
if (error) {
printf("%s is not an unsigned integer\n", argv[2]) ;
exit(1) ;
}
c = a + b ;
printf("%d + %d = %d\n",a,b,c) ;
}