qfedu-c-level/day12/d3.c

15 lines
461 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 格式化输出字符串 sprintf(char *buf, const char *format, ...)
// 函数返回输出到 buf 字符串,并返回 buf 的字符串长度
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char buf[20] = "";
// ret 返回字符串 长度
// %0nd : n为输出长度不足n位的前面位置补0
int ret = sprintf(buf, "%d 年 %02d 月 %d 日", 2023, 7, 18);
printf("ret = %d,%s\n", ret, buf);
return 0;
}