【发布时间】:2020-08-29 10:10:15
【问题描述】:
我挑战自己制作一个需要一个 int 的程序,它必须打印相应的 ASCII 字母,如下所示:如果数字是 65,它应该打印出 A 等等。但我不知道该怎么做。到目前为止,这是我的代码:
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
for (int i = 65; i < 81; i++)
{
printf("%s\n", i);
}
}
我需要在string b = NULL; 和printf("%s\n", b); 之间的位置添加某种函数,但我不知道应该使用哪个函数。最后,它应该按顺序打印出所有字母表,每个字母都有自己的一行。如果您碰巧知道可以帮助我的功能,请告诉我。
附言
如果我按照上面的示例进行操作,我会收到以下错误消息:
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow try.c -lcrypt -lcs50 -lm -o try
try.c:12:18: error: format specifies type 'char *' but the argument has type 'int' [-Werror,-Wformat]
printf("%s\n", i);
~~ ^
%d
1 error generated.
<builtin>: recipe for target 'try' failed
make: *** [try] Error 1
【问题讨论】: