与音频会话编程相关的许多常量实际上是四字符串(音频会话服务参考).这同样适用于从函数返回的OSStatus代码AudioSessionGetProperty.
问题是,当我尝试打开这些东西时,它们看起来像1919902568.我可以将其插入计算器并打开ASCII输出,它会告诉我"roch",但必须有一个编程方式做这个.
我使用以下块在我的一个C函数中取得了有限的成功:
char str[20];
// see if it appears to be a four-character code
*(UInt32 *) (str + 1) = CFSwapInt32HostToBig(error);
if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) {
str[0] = str[5] = '\'';
str[6] = '\0';
} else {
// no, format as integer
sprintf(str, "%d", (int)error);
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是从当前函数中抽象出这个特性,以便在别处使用它.我试过了
char * fourCharCode(UInt32 code) {
// block
}
void someOtherFunction(UInt32 foo){
printf("%s\n",fourCharCode(foo));
}
Run Code Online (Sandbox Code Playgroud)
但这给了我"à*€/3íT:ê*€/ +€/",而不是"roch".我的C fu不是很强大,但我的预感是上面的代码试图将内存地址解释为字符串.或者可能存在编码问题?有任何想法吗?