比方说,我想将整个代码块输入一个命令:
int k = 0;
for (k = 0; k < 50; k++)
{
sprintf(buf, "M LR 10 -10\n"); //We put the string "M L 10" into the string buffer.
write(sock, buf, strlen(buf)); //We send the buffer into the socket.
memset(buf, 0, 80); //Clear the buffer, set buffer to value 0.
read(sock, buf, 80); //Read from the socket to get the results.
int lme, rme;
sprintf(buf, "S MELR\n"); //sensor command to find ME values
write(sock, buf, strlen(buf)); //sends the buffer …Run Code Online (Sandbox Code Playgroud) c ×1