I am trying to convert input string from pipe to hexadecimal, the input is 8KB but converted hex is just 6KB, I print out normal input and the correct lines are coming. I also try to write that hex string to shared memory, maybe my problem is the memory pointer but I'm not sure.
But, it prints out hex correctly for small inputs, I am stuck.
String to hex:
void stringtohex(char *input, char *output) {
int loop;
int i;
i = 0;
loop = 0;
while (input[loop] != '\0') {
sprintf((char*)(output + i), "%02X", input[loop]);
loop += 1;
i += 2;
}
//insert NULL at the end of the output string
output[i++] = '\0';
}
Reading part:
int num;
char s[BUFFER_SIZE];
while ((num = read(fd, s, BUFFER_SIZE)) > 0) {
//fprintf(stderr, "input: \n%s\n", s);
int len = strlen(s);
char hex[(len * 2) + 1];
stringtohex(s, hex);
sprintf(ptr_child_2, "%s", hex);
ptr_child_2 += strlen(hex);
}
here ptr
is a void *
mapped to shared memory.