读书人

怪怪的初级题解决方案

发布时间: 2012-02-29 16:44:10 作者: rapoo

怪怪的初级题
想输出这样的
1111111111111111
N)ew
(O)pen
Save (F1)
Save (A)s
Close (ESC)

可以下面这个却不会变成这样,语法通过,希望各位指点,我用一个较小的数组和\b却可以正常。。不知道这是为什么?

#include <bios.h>
#include <stdio.h>


void Initial(char RootC[][11])
{
int i;
clrscr();
textcolor(0);
textbackground(7);
cprintf( "\n\r111111111111111111111111111111 ");


cprintf( "\n\b\b\b\b ");
for(i=0;i <4;i++)
{
cprintf( "%s ",RootC[i]);
cprintf( "\n\b\b\b\b\b\b\b\b\b\b\b ");
}
cprintf( "%s ",RootC[4]);

}
void main()

{ char RootC[5][11]={ "(N)ew ",
"(O)pen ",
"Save (F1) ",
"Save (A)s ",
"Close (ESC) "};
Initial(RootC);
}

[解决办法]
以前我也没有用过cprintf,应该不是标准C的吧
_cprintf, _cwprintf
Formats and prints to the console.


int _cprintf(
const char * format [,
argument] ...
);
int _cwprintf(
const wchar * format [,
argument] ...
);
Parameters
format
Format-control string.
argument
Optional parameters.
Return Value
_cprintf and _cwprintf return the number of characters printed.

Remarks
The _cprintf and _cwprintf functions format and print a series of characters and values directly to the console, using the _putch and _putwch functions, respectively, to output characters. Each argument (if any) is converted and output according to the corresponding format specification in format. The format has the same form and function as the format parameter for the printf function. Unlike the fprintf, printf, and sprintf functions, neither _cprintf nor _cwprintf translates line feed characters into carriage returnline feed (CR-LF) combinations when output.

An important distinction is that _cwprintf displays Unicode characters when used in Windows NT. Unlike _cprintf, _cwprintf uses the current console locale settings.

这是我在MSDN上找到的
[解决办法]
%*.*s ,前边的*定义的是总的宽度,后边的定义的是输出的个数。


如果后边的比前边的小,则使用空格在左侧补够m位。

ps:%m.nf这个格式总该熟悉吧,再想下上面的。。

读书人网 >C语言

热点推荐