格式'%s'的预期类型“的char *”的说法 [英] format ‘%s’ expects argument of type ‘char *’
本文介绍了格式'%s'的预期类型“的char *”的说法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#包括LT&;&stdio.h中GT;
诠释的main()
{
INT I,J,K;
烧焦ST;
的printf(请输入字符串\\ n);
scanf函数(%S,ST);
的printf(输入的字符串为%s \\ n,ST);
}
〜
编译上面的程序给我一个警告
警告:格式'%s'的预期类型的char *'的说法,但参数2的类型'诠释'[-Wformat]
palindrom.c:8:1:警告:格式'%s'的预期类型的char *'的说法,但参数2的类型'诠释'[-Wformat]
什么是我在这里做什么错误?当我运行
./a.out
输入字符串
kiaaa
输入的字符串(空)
*的编辑* 的
好吧,我得到了点
这里是code的另一个版本现在我修正后运行
#包括LT&;&stdio.h中GT;
诠释的main()
{
INT I,J,K;
字符* ST;
的printf(请输入字符串\\ n);
scanf函数(%S,ST);
的printf(输入的字符串为%s \\ n,ST);
}
但输出输入字符串
基达
输入的字符串(空)
解决方案
字符ST
是单个字符。您code的其余部分来看,你可能是为了宣布一个字符数组:
字符ST [80];
#include<stdio.h>
int main ()
{
int i,j,k;
char st;
printf("enter string\n");
scanf("%s",st);
printf("the entered string is %s\n",st);
}
~
compiling above program gives me a warning
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]
What is the mistake I am doing here? and when I run it ./a.out
enter string
kiaaa
the entered string is (null)
*edit * Ok I got the point here is another version of code which now I run after correction
#include<stdio.h>
int main ()
{
int i,j,k;
char *st;
printf("enter string\n");
scanf("%s",st);
printf("the entered string is %s\n",st);
}
but the output is
enter string
kida
the entered string is (null)
解决方案
char st
is a single character. Judging by the rest of your code, you probably intended to declare an array of characters:
char st[80];
这篇关于格式'%s'的预期类型“的char *”的说法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文