#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* convertToHexString(const char* hexData) {
int length = strlen(hexData) / 3;
char* result = malloc((length + 1) * sizeof(char));
int j = 0;
for (int i = 0; i < strlen(hexData); i += 3) {
if (hexData[i] == ' ') {
continue;
}
char hex[3];
strncpy(hex, &hexData[i], 2);
hex[2] = '\0';
int decimal = (int)strtol(hex, NULL, 16);
result[j] = (char)decimal;
j++;
}
result[j] = '\0';
return result;
}
int main() {
char hexData[] = "68 74 74 70 73 3a 2f 2f 77 65 63 68 61 74 76 32 2e 65 62 75 6c 6c 70 6f 77 65 72 2e 63 6f 6d 2f 75 73 65 72 2f 62 61 6c 61 6e 63 65 3f 63 6f 64 65 3d 30 38 31 66 37 69 30 30 30 6f 4c 33 65 51 31 48 37 75 30 30 30 31 61 45 69 68 33 66 37 69 30 74 26 73 74 61 74 65 3d";
char* string = convertToHexString(hexData);
printf("转换结果:%s\n", string);
free(string);
return 0;
}