#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); }
但是,它在运行时的行为相同.
解决方法
原文地址:https://www.jb51.cc/c/112937.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。