格式'%s'的预期类型“的char *'的说法,但参数2的类型'字符(*)[64] [英] format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[64]

查看:483
本文介绍了格式'%s'的预期类型“的char *'的说法,但参数2的类型'字符(*)[64]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 C 创建一个程序,我在我的code这行:

I'm creating a program using C, and I have this line in my code :

scanf("%s", &path);

当我编译源文件,我得到这样的警告:

When I compile the source file, I get this warning :

main.c:84:2: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[64]’ [-Wformat]

这是路径声明变量:

char path[64];

为什么我看到这个错误?我怎么能解决呢?

Why I'm seeing this error? And how can I solve it ?

推荐答案

这是阵列已经是一个类似指针的对象(如dreamlax指出)。你并不需要在&安培; 运营商,因为声明

An array is already a pointer-like object (as dreamlax points out). You don't need the & operator, since declaring

char path[64];

等同于路径设置为指向内存的64字节区域。

is equivalent to setting path to a pointer to a 64-byte region of memory.

这篇关于格式'%s'的预期类型“的char *'的说法,但参数2的类型'字符(*)[64]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆