在c语言中,如何使输出的结果 居中

AzureSky_xjc 2006-11-01 11:31:42
比如 printf("*******************欢迎来csdn*******************")
这句话在输出后是居中显示的
...全文
12139 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jixingzhong 2006-11-01
  • 打赏
  • 举报
回复
你可以输出几个 \t 字符控制光标到指定列,
或者是输出 若干个空格,
由于字符界面是80*25 的,
所以,
可以这样居中:
#include <stdio.h>
#include <stdlib.h>

//#define MAX 50

int main()
{
printf("%*s\n", 40, "Hello"); //输出40个空格,使得列居中
printf("%*s\n", 40, "World");
system("PAUSE");
return 0;
}
jixingzhong 2006-11-01
  • 打赏
  • 举报
回复
要居中,
就多输出几个空格 等空白字符就可以了 ...
AzureSky_xjc 2006-11-01
  • 打赏
  • 举报
回复
我才学了几个星期c语言,楼上的代码,我有点不明白,m我明白是什么,但后面的.......$str,是什么意思
weijiangshanwww 2006-11-01
  • 打赏
  • 举报
回复
printf("%ms\n",$str);
=============
printf("%ms\n",str);
刚刚的LINUX下的,写错了,下面的WINDOWS下的
weijiangshanwww 2006-11-01
  • 打赏
  • 举报
回复


printf("%ms\n",$str);

m的值可以自己调整。以满足居中的要求。



飞哥 2006-11-01
  • 打赏
  • 举报
回复
是不是可以设置缓冲区大小来弄啊--

SetConsoleScreenBufferSize
The SetConsoleScreenBufferSize function changes the size of the specified console screen buffer.

BOOL SetConsoleScreenBufferSize(
HANDLE hConsoleOutput, // handle to console screen buffer
COORD dwSize // new size in character rows and cols.
);

Parameters
hConsoleOutput
Handle to a console screen buffer. The handle must have GENERIC_WRITE access.
dwSize
Specifies a COORD structure containing the new size, in rows and columns, of the screen buffer. The specified width and height cannot be less than the width and height of the screen buffer's window. The specified dimensions also cannot be less than the minimum size allowed by the system. This minimum depends on the current font size for the console (selected by the user) and the SM_CXMIN and SM_CYMIN values returned by the GetSystemMetrics function.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in wincon.h.
Import Library: Use kernel32.lib.

argenCHN 2006-11-01
  • 打赏
  • 举报
回复
输出空格来调整
lockhall 2006-11-01
  • 打赏
  • 举报
回复 3
自己调整吧?
不过如果换分辨率的话可能又不居中了吧??
飞哥 2006-11-01
  • 打赏
  • 举报
回复
都是拿空格来对齐

windows下面没有居中的

ios::left,ios::right 倒是有

--

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧