编译器显示此代码的警告

时间:2015-01-05 23:45:02

标签: c string pointers data-structures

我的编译器(clang)显示以下消息:

  

expected-warning {{format指定类型'char ',但参数的类型为'char()[5]'}}

从以下代码(问候程序):

/*
 * Program: gretting2.c
 * Utility: Display a greeting with your name.
 * Author:  Adrián Garro.
 */

#include <stdio.h>

int main () {

    char name[0];

    printf("-------------------\n");
    printf("Write your name: \n");
    printf("-------------------\n");

    scanf("%s", &name);
    /*
    expected-warning{{format specifies type 'char *' but the argument has type 'char (*) [5]'}}
    */

    printf("------------------------------------\n");
    printf("Hello %s, nice to meet you\n",name);
    printf("------------------------------------\n");
}

我该如何解决?如果有人可以帮助我,我将不胜感激。

0 个答案:

没有答案