You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
876 B
C

#include <stdio.h>
#include <string.h>
int read_bytes(char *out_byte_array, int max_n) {
char buf[2];
int i = 0;
while(((buf[0] = (char)getchar())!= EOF) && (buf[0] != '\n') && (i < max_n)) {
buf[1] = getchar();
if (buf[1] == EOF)
return -1;
sscanf(buf, "%hhx", out_byte_array + i);
i++;
}
// number of read characters
return i;
}
void print_bytes(char *byte_array, int n) {
for (int i = 0; i < n; ++i) {
printf("%hhx", byte_array[i]);
}
}
int print_str_bytes(char *str, int n) {
for (int i = 0; i < n; ++i) {
printf("%hhx", str[i]);
}
}
/*int main() {
char meow[10];
int n = read_bytes(meow, 10);
print_bytes(meow, n);
char *nya = "meow meow ctagirl uwu";
print_str_bytes(nya, strlen(nya));
}*/