格式’%s’期望类型为’char *’的参数
发布时间:2020-12-16 06:02:23 所属栏目:百科 来源:网络整理
导读:#include stdio.hint main(void){ int i,j,k; char st; printf("enter stringn"); scanf("%s",st); printf("the entered string is %sn",st);} 编译上面的程序给了我一个警告: warning: format '%s' expects argument of type 'char *',but argument 2 ha
#include <stdio.h> int main(void) { int i,j,k; char st; printf("enter stringn"); scanf("%s",st); printf("the entered string is %sn",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 stringn"); scanf("%s",st); } 但是,它在运行时的行为相同. 解决方法
char st是一个单一的字符.根据您的其余代码,您可能打算声明一个字符数组:
char st[80]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |