A
Andrea
Hi,
suppose that I have a string that is an hexadecimal number, in order
to print this string I have to do:
void print_hex(unsigned char *bs, unsigned int n){
int i;
for (i=0;i<n;i++){
printf("%02x",bs);
}
}
where bs is an hexadecimal string, now i want to create a function
that given bs return a printable string containing the hexadecimal
value of bs, i tried doing this:
int hex2str(char* digest, char* result,int len){
int i;
char *app=malloc(sizeof(char));
result=malloc(strlen(digest));
for (i=0;i<len;i++){
sprintf(app,"%02x",digest);
strcat(result,app);
}
}
When i print result it seems to give me some polluted string with some
unprintable character,
any suggestion?
Thanks in advance,
Andrea
suppose that I have a string that is an hexadecimal number, in order
to print this string I have to do:
void print_hex(unsigned char *bs, unsigned int n){
int i;
for (i=0;i<n;i++){
printf("%02x",bs);
}
}
where bs is an hexadecimal string, now i want to create a function
that given bs return a printable string containing the hexadecimal
value of bs, i tried doing this:
int hex2str(char* digest, char* result,int len){
int i;
char *app=malloc(sizeof(char));
result=malloc(strlen(digest));
for (i=0;i<len;i++){
sprintf(app,"%02x",digest);
strcat(result,app);
}
}
When i print result it seems to give me some polluted string with some
unprintable character,
any suggestion?
Thanks in advance,
Andrea