A
anon.asdf
In terms of efficieny:
Is it better to use multiple putchar()'s after one another as one gets
to new char's
OR
is it better to collect the characters to a char-array first, and then
use puts() to print to screen
????
/******* ExampleA **********/
/**** collect chars and then call puts ****/
char symbols[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'};
#define uchar2hex(char_ptr, str_ptr) \
*str_ptr++ = symbols[((unsigned char)*char_ptr) >> 4]; \
*str_ptr++ = symbols[((unsigned char)*char_ptr++) & 0xF]; \
*str_ptr++ = ' ';
{
int i;
char source[29] = "asdfasdfasdfasdfsadfasdfasdf";
char *src_ptr = source;
char dest[29];
char *dest_ptr = dest;
for (i = 0; i < 29; i++) {
uchar2hex(src_ptr, dest_ptr);
}
*dest_ptr = '\0';
puts(dest);
}
/********* ExampleB *************/
/***** putchar() as each new char is encountered ******/
char symbols[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'};
#define uchar2hex2(char_ptr, str_ptr) \
putchar(*str_ptr++ = symbols[((unsigned char)*char_ptr) >> 4]); \
putchar(*str_ptr++ = symbols[((unsigned char)*char_ptr++) & 0xF]); \
putchar(*str_ptr++ = ' ');
{
int i;
char source[29] = "asdfasdfasdfasdfsadfasdfasdf";
char *src_ptr = source;
char dest[29];
char *dest_ptr = dest;
for (i = 0; i < 29; i++) {
uchar2hex2(src_ptr, dest_ptr);
}
*dest_ptr = '\0';
}
Is it better to use multiple putchar()'s after one another as one gets
to new char's
OR
is it better to collect the characters to a char-array first, and then
use puts() to print to screen
????
/******* ExampleA **********/
/**** collect chars and then call puts ****/
char symbols[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'};
#define uchar2hex(char_ptr, str_ptr) \
*str_ptr++ = symbols[((unsigned char)*char_ptr) >> 4]; \
*str_ptr++ = symbols[((unsigned char)*char_ptr++) & 0xF]; \
*str_ptr++ = ' ';
{
int i;
char source[29] = "asdfasdfasdfasdfsadfasdfasdf";
char *src_ptr = source;
char dest[29];
char *dest_ptr = dest;
for (i = 0; i < 29; i++) {
uchar2hex(src_ptr, dest_ptr);
}
*dest_ptr = '\0';
puts(dest);
}
/********* ExampleB *************/
/***** putchar() as each new char is encountered ******/
char symbols[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'};
#define uchar2hex2(char_ptr, str_ptr) \
putchar(*str_ptr++ = symbols[((unsigned char)*char_ptr) >> 4]); \
putchar(*str_ptr++ = symbols[((unsigned char)*char_ptr++) & 0xF]); \
putchar(*str_ptr++ = ' ');
{
int i;
char source[29] = "asdfasdfasdfasdfsadfasdfasdf";
char *src_ptr = source;
char dest[29];
char *dest_ptr = dest;
for (i = 0; i < 29; i++) {
uchar2hex2(src_ptr, dest_ptr);
}
*dest_ptr = '\0';
}