Add error message for illegal input.

This commit is contained in:
tim.schubert@tu-bs.de 2016-10-26 22:28:04 +02:00
parent 089fe12128
commit 1f9785e9c8

View file

@ -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;