如何在 C 中处理给定的外部函数
How to handle given extern function in C
我得到了名为 statPrint 的函数来处理系统调用 stat() 的打印。该函数由另一个 .o 文件提供。使用该函数编译我的实现时出现错误:
In function ‘main’:
statcall.c:9:19: error: expected expression before ‘,’ token
statPrint(argv[1]*,sb*);
^
statcall.c:9:19: error: incompatible type for argument 2 of ‘statPrint’
statcall.c:4:8: note: expected ‘struct stat *’ but argument is of type ‘struct stat’
extern statPrint(char*,struct stat*);
这是我的代码:
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
extern statPrint(char∗,struct stat∗);
int main(int argc, char *argv[])
{
struct stat sb;
stat(argv[1],&sb); ///argv[1] contains input from the terminal/shell
statPrint(argv[1]*,sb*);
}
我编译它(libstat 包含外部函数):
gcc -o statcall statcall.c libstat.o
如何消除错误?
您的功能需要char *
请提供
statPrint(argv[1],sb);
我真的没明白什么是argv[1]*
这一行没有意义:
statPrint(argv[1]*,sb*);
没有以 *
结尾的有效语法。
我想你想要:
statPrint(argv[1], &sb);
建议您阅读变量和指针的地址。
我得到了名为 statPrint 的函数来处理系统调用 stat() 的打印。该函数由另一个 .o 文件提供。使用该函数编译我的实现时出现错误:
In function ‘main’:
statcall.c:9:19: error: expected expression before ‘,’ token
statPrint(argv[1]*,sb*);
^
statcall.c:9:19: error: incompatible type for argument 2 of ‘statPrint’
statcall.c:4:8: note: expected ‘struct stat *’ but argument is of type ‘struct stat’
extern statPrint(char*,struct stat*);
这是我的代码:
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
extern statPrint(char∗,struct stat∗);
int main(int argc, char *argv[])
{
struct stat sb;
stat(argv[1],&sb); ///argv[1] contains input from the terminal/shell
statPrint(argv[1]*,sb*);
}
我编译它(libstat 包含外部函数):
gcc -o statcall statcall.c libstat.o
如何消除错误?
您的功能需要char *
请提供
statPrint(argv[1],sb);
我真的没明白什么是argv[1]*
这一行没有意义:
statPrint(argv[1]*,sb*);
没有以 *
结尾的有效语法。
我想你想要:
statPrint(argv[1], &sb);
建议您阅读变量和指针的地址。