-1
我希望能夠在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'「打印」到一個文件。你想使用'printf'嗎? – alain
[man fprintf](https://linux.die.net/man/3/fprintf)。投票結束這個簡單的錯字。 – Lundin