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

Reg*_*ser 14 c

#include <stdio.h>
int main(void)
{
    int i,j,k;
    char st;
    printf("enter string\n");
    scanf("%s", st);
    printf("the entered string is %s\n", st);
}
Run Code Online (Sandbox Code Playgroud)

编译上面的程序给了我一个警告:

warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat]
palindrom.c:8:1: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat]
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?

这是我运行时发生的事情:

$ ./a.out
enter string
kiaaa
the entered string is (null)
Run Code Online (Sandbox Code Playgroud)

编辑:

下面是代码(由另一个版本char st;char *st):

#include <stdio.h>
int main(void)
{
    int i,j,k;
    char *st;
    printf("enter string\n");
    scanf("%s", st);
    printf("the entered string is %s\n", st);
}
Run Code Online (Sandbox Code Playgroud)

但是,它在运行时的行为相同.

NPE*_*NPE 11

char st是一个单一的角色.根据代码的其余部分判断,您可能想要声明一个字符数组:

char st[80];
Run Code Online (Sandbox Code Playgroud)