Add error message for illegal input.
This commit is contained in:
parent
089fe12128
commit
1f9785e9c8
1 changed files with 9 additions and 5 deletions
12
netcalc.c
12
netcalc.c
|
@ -206,14 +206,18 @@ int server()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset(buf, 0, sizeof buf);
|
||||||
|
|
||||||
unsigned int result;
|
unsigned int result;
|
||||||
if (calc(first, second, op, &result) == -1) {
|
if (calc(first, second, op, &result) == -1) {
|
||||||
fprintf(stderr, "calc: invalid operator %c for %u and %u", op, first, second);
|
char *errormsg = "error: %u %c %u invalid\n";
|
||||||
continue;
|
fprintf(stderr, errormsg, op, first, second);
|
||||||
}
|
sprintf(buf, errormsg, first, op, second);
|
||||||
memset(buf, 0, sizeof buf);
|
} else {
|
||||||
printf("%u %c %u = %u\n", first, op, second, result);
|
printf("%u %c %u = %u\n", first, op, second, result);
|
||||||
sprintf(buf, "%u\n", result);
|
sprintf(buf, "%u\n", result);
|
||||||
|
|
||||||
|
}
|
||||||
if (send(c_fd, buf, sizeof buf, 0) == -1) {
|
if (send(c_fd, buf, sizeof buf, 0) == -1) {
|
||||||
perror("send");
|
perror("send");
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue