-
Notifications
You must be signed in to change notification settings - Fork 486
Expand file tree
/
Copy path4-add.c
More file actions
39 lines (33 loc) · 722 Bytes
/
4-add.c
File metadata and controls
39 lines (33 loc) · 722 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
/*
* File: 4-add.c
* Auth: Brennan D Baraban
*/
#include <stdio.h>
#include <stdlib.h>
/**
* main - Prints the addition of positive numbers,
* followed by a new line.
* @argc: The number of arguments passed to the program.
* @argv: An array of pointers to the arguments.
*
* Return: If one of the numbers contains symbols that are non-digits - 1.
* Otherwise - 0.
*/
int main(int argc, char *argv[])
{
int num, digit, sum = 0;
for (num = 1; num < argc; num++)
{
for (digit = 0; argv[num][digit]; digit++)
{
if (argv[num][digit] < '0' || argv[num][digit] > '9')
{
printf("Error\n");
return (1);
}
}
sum += atoi(argv[num]);
}
printf("%d\n", sum);
return (0);
}