c - 将 int 传递给需要 char* 的函数

标签 c linux

我想将 int 传递给需要 char * 的函数。

函数头如下所示:

void swapEndian(char *pElement, unsigned int uNumBytes)

并使用 int 调用函数(我知道,这行不通..)

int numLine;
swapEndian(numLine, sizeof(int));

那么我必须对 numline 做些什么才能将它传递给这个函数?

最佳答案

听起来好像你只是想要:

swapEndian( (char*) &numLine, sizeof(int) );

关于c - 将 int 传递给需要 char* 的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13309139/

相关文章:

c - 将 C 库与 Java、Ruby、Node、Python、Go、.NET 集成

c - 获取内核中的System32目录

c - 将二维数组传递给 C 中的 GTK 函数

linux - 如何在 Ubuntu crontab 中将文件从一台计算机复制到另一台计算机?

linux - 查找上次修改时间为 8 月的文件

c++ - Makefile 与 OpenMP : cannot specify -o with -c, -S 或 -E 与多个文件

c - 从 C 程序返回值是什么意思?

linux - 如何在shell中输出返回码?

c - 为什么系统调用 signal() 不调用处理程序?

linux - UNIX find 命令的奇怪行为