4.lika.18_test.coder 4.ilyas.18_test.coder

--- 4.lika.18_test.coder.fmt.c	2020-06-08 11:39:11.766116013 +0300
+++ 4.ilyas.18_test.coder.fmt.c	2020-06-08 11:39:11.735115678 +0300
@@ -1,27 +1,28 @@
 #1 "<stdin>"
-#include <stdio.h>
+#include <assert.h>
 #include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <errno.h>
-#include <sys/types.h>
+#include <sys/wait.h>
 #include <unistd.h>
-int main(int argc, char *argv[]) {
-    int i = 0;
-    while (1) {
-	char a = argv[2][i];
-	char b = argv[2][i];
-	for (int j = 7; j >= 0; j--) {
-	    int x = (a >> (j)) & 0x1;
-	    if (x == 1)
-		kill(atoi(argv[1]), SIGUSR2);
-	    else
-		kill(atoi(argv[1]), SIGUSR1);
-	    usleep(1000);
-	}
-	if (b == 0)
-	    break;
-	i++;
+void send_byte(pid_t pid, char byte) {
+    for (int i = 7; i >= 0; i--) {
+	int x = (byte >> (i)) & 0x1;
+	if (x == 1)
+	    kill(pid, SIGUSR2);
+	else
+	    kill(pid, SIGUSR1);
+	usleep(1000 * 10);
     }
+}
+int main(int argc, char *argv[]) {
+    int pid;
+    sscanf(argv[1], "%d", &pid);
+    char *s = argv[2];
+    for (int i = 0; i < strlen(s); i++)
+	send_byte(pid, s[i]);
+    send_byte(pid, '\0');
     return 0;
 }