c语言如何把函数作为参数,如何使用FILE作为C中函数的参数?

我正在学习C,而且我来自

Java背景.如果我能得到一些指导,我将不胜感激.这是我的代码:

#include

#include

#include

#include

int main(void)

{

char *str = "test text\n";

FILE *fp;

fp = fopen("test.txt", "a");

write(fp, str);

}

void write(FILE *fp, char *str)

{

fprintf(fp, "%s", str);

}

当我尝试编译时,我收到此错误:

xxxx.c: In function ‘main’:

xxxx.c:18: warning: passing argument 1 of ‘write’ makes integer from pointer without a cast

/usr/include/unistd.h:363: note: expected ‘int’ but argument is of type ‘struct FILE *’

xxxx.c:18: error: too few arguments to function ‘write’

xxxx.c: At top level:

xxxx.c:21: error: conflicting types for ‘write’

/usr/include/unistd.h:363: note: previous declaration of ‘write’ was here

有什么想法吗?谢谢你的时间.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 迁移至php7.1+mysql5.6+nginx的修改项目 已修改 : /phpcms/libs/classes/checkcode.class.php 已修改 : /phpcms/libs/classes/db_factory.class.php 已增加 : /phpcms/libs/classes/db_mysqli.class.php 已修改 : /phpcms/libs/classes/model.class.php 已修改 : /phpcms/libs/classes/template_cache.class.php 已修改 : /phpcms/libs/classes/update.class.php 已修改 : /phpcms/libs/functions/global.func.php 已修改 : /phpcms/modules/admin/cache_all.php 已修改 : /phpcms/modules/content/fields/editor/output.inc.php 已修改 : /phpcms/modules/content/fields/title/output.inc.php 2. 函数htmlspecialchars()在php7下严格校验编码,导致空白,修改为new_html_special_chars()方法: 已修改 : /phpcms/modules/content/fields/content_form.class.php 已修改 : /phpcms/modules/content/fields/omnipotent/field_edit_form.inc.php 已修改 : /phpcms/modules/content/fields/textarea/field_edit_form.inc.php 已修改 : /phpcms/modules/yp/fields/omnipotent/field_edit_form.inc.php 已修改 : /phpcms/modules/yp/fields/textarea/field_edit_form.inc.php 已修改 : /phpcms/modules/yp/fields/title/output.inc.php 已修改 : /phpcms/modules/yp/fields/yp_form.class.php 所有以上修改/增加的文件,均在下面压缩包,建议下载后对比查看,不建议直接替换; phpcmsV9升级php7修改文件 [点击直接下载] 其global.func.php仅修改不可替换,请自行对比文件改动的地方; 3.修改database.php的type值为mysqli; 注意事项: A.php7.1对函数参数个数严格校验,对函数形参一定要赋默认值,否则直接Fatal error: Uncaught ArgumentCountError: Too few arguments to function; B.htmlspecialchars严格编码,以前在php5.2下正常使用的,需要修改为 new_html_special_chars() 具体函数定义见 global.func.php; C.数据库5.6对老版本5.0的listorder-1问题,将字段设置为有符号即可;

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值