Fix string parsing bugs which prevented write commands from working correctly
diff --git a/rmihidtool/main.cpp b/rmihidtool/main.cpp
index 8fcb858..1202d07 100644
--- a/rmihidtool/main.cpp
+++ b/rmihidtool/main.cpp
@@ -85,10 +85,8 @@
 	}
 
 	while (input[i] != '\0') {
-		++i;
-		if (input[i] == ' ') {
+		if (input[++i] == ' ')
 			break;
-		}
 	}
 	end = &input[i];
 
@@ -97,13 +95,11 @@
 
 	*endpp = end;
 	strncpy(result, start, end - start);
-	result[end - start + 1] = '\0';
+	result[end - start] = '\0';
 
 	return 1;
 }
 
-
-
 void interactive(RMIDevice * device, unsigned char *report)
 {
 	char token[256];
@@ -157,8 +153,7 @@
 				memset(report, 0, 256);
 				while (find_token(start, token, &end)) {
 					start = end;
-					report[index] = strtol(token, NULL, 0);
-					++index;
+					report[index++] = strtol(token, NULL, 0);
 					++len;
 				}
 
@@ -220,6 +215,7 @@
 	char * data = NULL;
 	char * start;
 	char * end;
+	int i = 0;
 
 	memset(&sig_cleanup_action, 0, sizeof(struct sigaction));
 	sig_cleanup_action.sa_handler = cleanup;
@@ -298,11 +294,12 @@
 			print_buffer(report, len);
 			break;
 		case RMIHIDTOOL_CMD_WRITE:
+			i = 0;
 			start = data;
 			memset(report, 0, sizeof(report));
 			while (find_token(start, token, &end)) {
 				start = end;
-				report[index++] = (unsigned char)strtol(token, NULL, 0);
+				report[i++] = (unsigned char)strtol(token, NULL, 0);
 				++len;
 			}