while ((n = Readline (connfd, buf, sizeof(buf)-1)) > 0) { char ch; int byte; buf[n] = '\0'; if (sscanf(buf,"%c %d",&ch,&byte) < 2 || sscanf(buf,"%c %d",&ch,&byte) > 2) { snprintf (buf, sizeof(buf), "ER\r\n"); Writen (connfd, buf, strlen(buf)); } else { if(connection==children) { snprintf (buf, sizeof(buf), "C\r\n"); Writen (connfd, buf, strlen(buf)); #ifdef TRACE err_msg("(%s) info - Max children's number(%d) reached, child %d rejected\r\n", prog, children, children+1, getpid()); #endif Close(connfd); } else(connection 0) { char op1; int a, b, q; buf[n] = '\0'; if (sscanf(buf,"%c %d %d",&op1,&a,&b) < 3 || sscanf(buf,"%c %d %d",&op1,&a,&b) > 3) snprintf (buf, sizeof(buf), "E\r\n"); else { if(op1=='+') snprintf (buf, sizeof(buf), "=%d\r\n", a+b); if(op1=='-') snprintf (buf, sizeof(buf), "=%d\r\n", a-b); if(op1=='*') snprintf (buf, sizeof(buf), "=%d\r\n", a*b); if(op1=='/') { q=a/b; if(q!=0) snprintf (buf, sizeof(buf), "=%d\r\n", a/b); else snprintf (buf, sizeof(buf), "U\r\n"); } } Writen (connfd, buf, strlen(buf)); } } } } }