1

私が持っているものを16進数に変更する必要があり、16進数値を取り込む必要があるためstringList、内部でそれを行う必要があります。たとえば、「5」と「A」が含まれている場合、0x5A を に渡したいと思います。MyFunctionWriteI2CstringListWriteI2C

char* stringList[5]; // array of strings (max 5 strings)
char* (*stringListPtr); // pointer to a string

void MyFunction(char* (char* (*stringListPtr))
{
    WriteI2C(a hex value); // ex: WriteI2C(0x5A);
}
4

1 に答える 1

2

Can you use NUL-terminated arrays of char (a. k. a. C strings)? If so:

const char *str = "5A";
int val = strtol(str, NULL, 16);
WriteI2C(val);

If not, you may want to make a NUL-terminated copy, or to reinvent the wheel (note: don't reinvent the wheel):

int ch2hex(char ch)
{
    if (isdigit(ch)) return ch - '0';
    if (islower(ch)) return ch - 'a' + 10;
    if (isupper(ch)) return ch - 'A' + 10;
    // if this is reached, something very nasty is going on
}

int str2hex(char arr[2])
{
    return (ch2hex(arr[0]) << 4) | ch2hex(arr[1]);
}
于 2013-02-06T21:51:35.690 に答える