编译环境
Win7(x64) + DMC(x86) v8.57
-
Win7下安装DMD2.7,安装时勾选DMC,忽略64位(因为需要安装Visual Studio 2013/2015),假设DMC最终安装在D:\Dlang\DMC目录
-
安装Notepad++及NppExec插件,NppExec的Execute ... --> Command设置为 D:\Dlang\DMC\dm\bin\dmc.exe $(FULL_CURRENT_PATH)
-
用Notepad++打开C代码文件,按Ctrl + F6 编译生成同名.exe文件
代码
/*
filename: ex01.c
21天C语言代码训练营(第一天)
http://www.jianshu.com/p/d8a5712a9b08
生成30行星号(*)组成的金字塔
*/
#include <stdio.h>
#include <string.h>
#define CHAR_BLANK 32
#define CHAR_ZERO 48
#define TIMES 30
int main()
{
char *star = "**", stars[2 * TIMES + 1] = "*";
char *blank = "", format[] = "%00s%s%00s\n";
int i = 1, ten = 0;
for (; i <= TIMES; i++) {
ten = (TIMES - i) / 10;
format[1] = format[7] = (ten == 0) ? CHAR_BLANK : ten + CHAR_ZERO; /*十位*/
format[2] = format[8] = (TIMES - i) % 10 + CHAR_ZERO; /*个位*/
printf(format, blank, stars, blank);
strcat(stars, star); /*每行增加两个*/
}
return 0;
}
网友评论