【发布时间】:2017-03-02 13:37:59
【问题描述】:
我希望能够在 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“打印”到文件。你想使用printf吗? -
man fprintf。投票结束这是一个简单的错字。