Working on writing two functions - one to convert ascii to hexadecimal and then vice-versa. Encountered something very very odd... With the printf(); statement commented out in the Asc2Hex function, it doesn't work. If I uncomment it, it works... Any idea? And if anyone knows of a better way to do this conversion, please do let me know.
#include <stdio.h>
#include <string.h>
char *Asc2Hex(char *);
int main()
{
char *test = Asc2Hex("ABCDEFG");
printf("Test: %s\n",test);
}
char *Asc2Hex(char *data){
int i, len = strlen(data);
char buffer[len+1];
char *pbuffer = buffer;
//printf("String: %s\n",data);
for(i = 0; i < (len * sizeof(char)); i++){
sprintf(pbuffer+i*2, "%x",*(data+i));
}
return pbuffer;
}