[英]Print out character in c
我希望能够按如下所示打印出c中字符的值:
fprintf("%c", alphabet[val]);
,其中字母初始化为
for(i = 0; i < 26; i++){
alphabet[i] = i + 65;
}
但是,此行出现以下错误:
encode.c: In function ‘main’:
encode.c:76:13: warning: passing argument 1 of ‘fprintf’ from incompatible pointer type [-Wincompatible-pointer-types]
fprintf("%c", alphabet[val]);
^
In file included from encode.c:1:0:
/usr/include/stdio.h:356:12: note: expected ‘FILE * restrict {aka struct _IO_FILE * restrict}’ but argument is of type ‘char *’
extern int fprintf (FILE *__restrict __stream,
^
encode.c:76:19: warning: passing argument 2 of ‘fprintf’ makes pointer from integer without a cast [-Wint-conversion]
fprintf("%c", alphabet[val]);
^
In file included from encode.c:1:0:
/usr/include/stdio.h:356:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
extern int fprintf (FILE *__restrict __stream,
^
encode.c:76:5: warning: format not a string literal and no format arguments [-Wformat-security]
fprintf("%c", alphabet[val]);
^
如何打印出这样的角色?
仔细检查您的代码。 对于声明
fprintf("%c", alphabet[val]);
文件指针在哪里? 它不见了。 您必须提供要查看其输出的文件指针,例如
fprintf(fp, "%c", alphabet[val]);
其中, fp
是文件指针(类型为FILE *
),通常由fopen()
返回,有关更多详细信息,请参见手册页 。
如果您希望打印输出到达stdout
,即标准输出,请使用printf()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.