作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在读一本关于 C 的书,它要求我做的问题是:
Write a program that uses printf to display the following picture on the screen
然后是一个带星号的复选标记。因此,我首先想到的是编写一堆使用格式宽度说明符的 printf() 语句。所以我想出了这个:
int main() {
printf("This program prints a checkmark using asteriks\n");
char asterik = '*';
printf("%10c\n", asterik);
printf("%9c\n", asterik);
printf("%8c\n", asterik);
printf("%7c\n", asterik);
printf("%6c\n", asterik);
printf("%c %3c\n", asterik, asterik);
printf("%2c %c\n", asterik, asterik);
printf("%3c\n", asterik);
return 0;
}
我知道这段代码很丑陋,恶心了所有 9 码,但我真的想知道是否有一种更有效、更干净的方法?我不确定作者是否打算这样写,考虑到这一课是在第二章中提出的,我们只是回顾了一些非常基本的事情,与此无关。 (多亏了K&R,我只记得如何调整宽度)
最佳答案
只有一个字符串文字可能会更好,如下所示:
const char checkmark[] =
" *\n"
" * \n"
" * \n"
"* * \n"
" * * \n"
" * \n"
;
printf("%s", checkmark);
关于c - 更有效的写法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29526040/
我正在尝试更改 NSAttributedString 中的写入方向。但是,我真的很难弄清楚该怎么做。 CTFontRef fontRef = CTFontCreateWithName((CFStrin
环境准备 数据库版本:MySQL 5.7.20-log 建表 SQL DROP TABLE IF EXISTS `t_ware_sale_statistics`; CREATE TABLE `t_wa
我确定有一种更惯用的 ruby 方式来编写下面的代码: @var = obj['blah'] unless obj['blah'].nil? 我有很多事情要做(见下文),一定有更好的方法! @nu
我是一名优秀的程序员,十分优秀!