-
cprintf
鎖定
- 外文名
- cprintf
- 功 能
- 送格式化輸出至屏幕
- 頭文件
- conio.h
- 説 明
- 非ANSI C標準
cprintf函數名
cprintf
cprintf功能
送格式化輸出至屏幕
cprintf簡介
説明:非ANSI C標準,在VC6.0、TC中均有conio.h這個頭文件。
下面的三個例子在TC2.0中運行通過。
程序例一:
#include<stdio.h> intmain(void) { /*clearthescreen*/ clrscr(); /*createatextwindow*/ window(10,10,80,25); /*outputsometextinthewindow*/ cprintf("Helloworld\r\n"); /*waitforakey*/ getch(); return0; }
程序例二:
#include<stdio.h> #include<conio.h> intmain(void) { clrscr();/*清屏函數*/ textbackground(2);/*文本的背景色*/ gotoxy(1,5);/*定位函數*/ cprintf("Outputatrow5column1\n"); textbackground(3); gotoxy(20,10); cprintf("Outputatrow10column20\n"); getch();/*等待用户按鍵*/ return0; }
程序例三:
#include<stdio.h> #include<conio.h> intmain(void) { intcolor; textcolor(10);/*設置文本顏色*/ for(color=0;color<8;color++) { gotoxy(1+color*3,1+color*2);/*定位函數*/ textbackground(color);/*設置背景顏色*/ cprintf("HelloWorld",color); } getch();/*等待用户按鍵*/ return0; }
下面的例子在VC6.0中運行通過。
#include<conio.h> #include<stdlib.h> intmain(void) { inti; for(i=0;i<20;i++) cprintf("%d\r\n",i); cprintf("\r\nPressanykeytoclearscreen"); getch(); system("cls"); cprintf("Thescreenhasbeencleared!"); getch(); system("cls"); return0; }
2. matlab中的cprintf
它的用法我來簡單翻譯一下:
語法: count = cprintf(style,format,...)
描述: CPRINTF 用指定格式(style)來處理指定的文檔
可用的格式名為
'Text' -- 默認:黑色black
'Keywords' -- 默認:藍色blue
'Comments' -- 默認:綠色green
'Strings' -- 默認:紫色purple
'UnterminatedStrings' -- 默認:暗紅darkred
'SystemCommands' -- 默認:橘色orange
'Errors' -- 默認:淡紅lightred
'Hyperlinks' -- 默認:帶下劃線的藍色underlined blue
其他顏色如下
'Black','Cyan','Magenta','Blue','Green','Red','Yellow','White'
注意: 以'-'開始的是下劃線,例如:
'-Blue' 是藍色的下劃線,與'Hyperlinks'相似
STYLE 也接受通用的RGB向量做為參數,在它前面加負號,表示下劃線,例如:
-[0,1,1]表示帶下劃線的藍綠色cyan
STYLE 不區分大小寫(case-insensitive),接受唯一的部分字符串
一些實用例子,如下所示
cprintf; % displays the demo
cprintf('text', 'regular black text');
cprintf('hyper', 'followed %s','by');
cprintf('k', '%d colored', 4);
cprintf('-comment','& underlined');
cprintf('err', 'elements\n');
cprintf('cyan', 'cyan');
cprintf('-green', 'underlined green');
cprintf(-[1,0,1], 'underlined magenta');
cprintf([1,0.5,0],'and multi-\nlineorange\n');
cprintf('string'); % same as fprintf('string') and cprintf('text','string')
附原文幫助文件:
% CPRINTF displays styledformatted text in the Command Window
%
% Syntax:
% count = cprintf(style,format,...)
%
% Description:
% CPRINTF processes the specified text usingthe exact same FORMAT
% arguments accepted by the built-in SPRINTFand FPRINTF functions.
%
% CPRINTF then displays the text in theCommand Window using the
% specified STYLE argument. The acceptedstyles are those used for
% Matlab's syntax highlighting (see: File /Preferences / Colors /
% M-file Syntax Highlighting Colors), andalso user-defined colors.
%
% The possible pre-defined STYLE names are:
%
% 'Text' - default: black
% 'Keywords' - default: blue
% 'Comments' - default: green
% 'Strings' - default: purple
% 'UnterminatedStrings' - default: dark red
% 'SystemCommands' - default: orange
% 'Errors' - default: light red
% 'Hyperlinks' - default: underlined blue
%
% 'Black','Cyan','Magenta','Blue','Green','Red','Yellow','White'
%
% Note: styles beginning with '-' will beunderlined. For example:
% '-Blue' is underlined blue, like'Hyperlinks';
% '-Comments' is underlined green etc.
%
% STYLE also accepts a regular Matlab RGBvector, that can be negated
% for underlining. For example: -[0,1,1]means underlined cyan.
%
% STYLE is case-insensitive and acceptsunique partial strings just
% like handle property names.
%
% CPRINTF by itself, without any inputparameters, displays a demo
%
% Example:
% cprintf; % displays the demo
% cprintf('text', 'regular black text');
% cprintf('hyper', 'followed %s','by');
% cprintf('k', '%d colored', 4);
% cprintf('-comment','& underlined');
% cprintf('err', 'elements\n');
% cprintf('cyan', 'cyan');
% cprintf('-green', 'underlined green');
% cprintf(-[1,0,1], 'underlined magenta');
% cprintf([1,0.5,0],'and multi-\nlineorange\n');
% cprintf('string'); % same as fprintf('string') and cprintf('text','string')
- 參考資料
-
- 1. Yair M. Altman的博客
- 2. 下載地址