格式‘%s’需要‘char *’类型的参数

问题描述

我正在尝试自己学习 C。我在编写一个简单的程序来接受名称并打印它时遇到了这个错误。小小的帮助会很棒。

#include <stdio.h>
int main()
{
    char name[10];
    printf("Enter the name :\t");
    scanf("%s",&name);
    printf("Name is %s",name);
    return 0;
}

当我尝试用 GCC 编译时

IOname.c: In function ‘main’:
IOname.c:6:10: warning: format ‘%s’ expects argument of type ‘char *’,but argument 2 has type ‘char (*)[10]’ [-Wformat=]
    6 |  scanf("%s",&name);
      |         ~^   ~~~~~
      |          |   |
      |          |   char (*)[10]
      |          char *

我不明白,请帮忙...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)