As from a file, where the file is, here is such an example text:
\x68\x65\x6c\x6c\x6f Get in unsigned char * How would I get this code
std::ifstream ifs(file); std::string content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); ifs.close(); har* hex = (har*)content.c_str(); But there is a difference if I do this.
char *hex = "\x68\x65\x6c\x6c\x6f"; cout << strlen(hex); // будет равняться 5 But if from a file, then, as I understand it, it reads all the characters, and the question is how then to get a hex from the file? Thank you in advance!
EDIT:
size_t ReadHexFile(FILE *inf, unsigned char *dest) { size_t count = 0; int n, u; if (dest == NULL) { unsigned int OneByte; while (true) { if ((n = fscanf(inf, "%hx", &OneByte)) == 1){ count++; }else{ break; } } } else { while ((n = fscanf(inf, "%hx", dest)) == 1) { dest++; } } if (n != EOF) { ; } return count; } unsigned char *file_get_contents(char *file){ FILE *inf = fopen(file, "rt"); int n = ReadHexFile(inf, NULL); rewind(inf); unsigned char *hex = (unsigned char *)malloc(n); ReadHexFile(inf, hex); fclose(inf); return hex; }
'\','x','6','8'in the file so directly? Or one character with code 0x68? - VladD