程序清單4.10_strings.c程序_《C Primer Plus》P73
阿新 • • 發佈:2018-06-17
urn print plus 格式 字符串 argv getchar() then () // strings.cpp : 定義控制臺應用程序的入口點。
//
/* strings.c -- 字符串的格式化 */
/*
時間:2018年06月16日 23:47:00
代碼:程序清單4.10_strings.c程序_《C Primer Plus》P73
目的:%-n.ms 文本左對齊 字段寬度為n, 字符個數為m;
*/
#include "stdafx.h"
#define BLURB "Authentic imitation!" // 簡介 "真實模仿"
int _tmain(int argc, _TCHAR* argv[])
{
printf("/%2s/\n", BLURB);
printf("/%24s/\n", BLURB);
printf("/%24.5s/\n", BLURB);
printf("/%-24.5s/\n", BLURB);
getchar();
return 0;
}
/*
在VS2010中運行結果:
------------------------------------------
/Authentic imitation!/
/ Authentic imitation!/
/ Authe/
/Authe /
----------------------------------------------------
總結:
/Authentic imitation!/ -- %2s
/ Authentic imitation!/ -- %24s
/ Authe/ -- %24.5s
/Authe / -- %-24.5s
-----------------------------------------------------
*
程序清單4.10_strings.c程序_《C Primer Plus》P73