程序清单4.10_strings.c程序_《C Primer Plus》P73

// 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
-----------------------------------------------------

*


猜你喜欢

转载自blog.51cto.com/13555061/2130108
今日推荐