forked from wenjun1055/c
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15.8.c
More file actions
31 lines (27 loc) · 716 Bytes
/
15.8.c
File metadata and controls
31 lines (27 loc) · 716 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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define MAXLINE 1024
int main(void)
{
int n, int1, int2;
char line[MAXLINE];
while ((n = read(STDIN_FILENO, line, MAXLINE))) {
line[n] = 0;
if (sscanf(line, "%d%d", &int1, &int2) == 2) {
sprintf(line, "%d\n", int1 + int2);
n = strlen(line);
if (write(STDOUT_FILENO, line, n) != n) {
printf("write error\n");
exit(-1);
}
} else {
if (write(STDOUT_FILENO, "invalid args\n", 13) != 13) {
printf("write error\n");
exit(-1);
}
}
}
return 0;
}