1
0
Fork 0
i237/src/print_helper.c

32 lines
671 B
C
Raw Normal View History

2016-09-26 17:33:02 +03:00
#include <stdio.h>
#include "print_helper.h"
2016-10-11 00:43:31 +03:00
int print_ascii_tbl (FILE *stream)
{
2016-09-26 17:33:02 +03:00
for (char c = ' '; c <= '~'; c++) {
2016-10-11 00:43:31 +03:00
if (!fprintf(stream, "%c ", c)) {
2016-09-26 17:33:02 +03:00
return 0;
}
}
2016-10-11 00:43:31 +03:00
2016-09-26 17:33:02 +03:00
return fprintf(stream, "\n");
}
2016-10-11 00:43:31 +03:00
int print_for_human (FILE *stream, const unsigned char *array, const int len)
{
2016-09-26 17:33:02 +03:00
for (int i = 0; i < len; i++) {
if (array[i] >= ' ' && array[i] <= '~') {
2016-10-11 00:43:31 +03:00
if (!fprintf(stream, "%c", array[i])) {
2016-09-26 17:33:02 +03:00
return 0;
}
} else {
2016-10-11 00:43:31 +03:00
if (!fprintf(stream, "\"0x%02x\"", array[i])) {
2016-09-26 17:33:02 +03:00
return 0;
}
}
}
2016-10-11 00:43:31 +03:00
2016-09-26 19:56:46 +03:00
return fprintf(stream, "\n");;
2016-09-26 17:33:02 +03:00
}