I need help to get the ascii to hex data output only for alphanumeric characters(excluding special characters).
Input String is: 86741-30011
Expected result is: 38363734313330303131
Actual Result is: 3836373431
Output breaks after non alphanumeric characters. It contains output string only until non alphanumeric characters.
Code:
int main(void){
char word[12] = { '8', '6','7','4','1','-','3','0','0','1','1'};
char outword[20];
int i, len;
len = strlen(word);
printf("Input string: %s\n", word);
//printf("Total length: %d\n", len);
if(word[len-1]=='\n') word[--len] = '\0';
for(i = 0; i<len; i++) {
if (isalnum(word[i]) == 0) {
printf("%c is not an alphanumeric character.\n", word[i]);
} else {
sprintf(outword+i*2 , "%02X", word[i]);
}
}
printf("Hex output:%s\n", outword); return 0;
}
Can anyone help me to get expected output?
Thanks in advance.