格式’%s’期望类型为’char *’的参数

#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);
}

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

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]

在这里做错了什么?

这是当我运行它会发生什么:

$./a.out
enter string
kiaaa
the entered string is (null)

编辑:

这是代码的另一个版本(使char * st; into char * st):

#include <stdio.h>
int main(void)
{
    int i,k;
    char *st;
    printf("enter string\n");
    scanf("%s",st);
}

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

解决方法

char st是一个单一的字符.根据您的其余代码,您可能打算声明一个字符数组:
char st[80];

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...