C语言中cprintf的用法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C语言中cprintf的用法相关的知识,希望对你有一定的参考价值。
急!!!!请各位高手指点一下如何利用cprintf输出彩色的结果,包括头文件啊,最好拿出一个简单的程序例子来,谢了~~~~
cprintf函数名: cprintf
功 能: 送格式化输出至屏幕
用 法: int cprintf(const char *format[, argument, ...]);
头文件: conio.h
说明:非ANSI C标准,在VC6.0、TC中均有conio.h这个头文件。
下面的三个例子在TC2.0中运行通过。
程序例一:
#include <stdio.h>
int main(void)
/* clear the screen */
clrscr();
/* create a text window */
window(10, 10, 80, 25);
/* output some text in the window */
cprintf("Hello world\r\n");
/* wait for a key */
getch();
return 0;
程序例二:
#include <stdio.h>
#include <conio.h>
int main(void)
clrscr(); /*清屏函数*/
textbackground(2); /*文本的背景色*/
gotoxy(1, 5); /*定位函数*/
cprintf("Output at row 5 column 1\n");
textbackground(3);
gotoxy(20, 10);
cprintf("Output at row 10 column 20\n");
getch(); /*等待用户按键*/
return 0;
程序例三:
#include <stdio.h>
#include <conio.h>
int main(void)
int color;
textcolor(10); /* 设置文本颜色 */
for(color=0;color<8;color++)
gotoxy(1+color*3,1+color*2); /* 定位函数 */
textbackground(color); /* 设置背景颜色 */
cprintf("Hello World",color);
getch(); /* 等待用户按键 */
return 0;
下面的例子在VC6.0中运行通过。
#include <conio.h>
#include<stdlib.h>
int main(void)
int i;
for (i = 0; i < 20; i++)
cprintf("%d\r\n", i);
cprintf("\r\nPress any key to clear screen");
getch();
system("cls");
cprintf("The screen has been cleared!");
getch();
system("cls");
return 0;
参考技术A
用 法: int cprintf(const char *format[, argument, ...]);
头文件: conio.h
说明:非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;
参考技术B 和printf()函数的作用和用法(除一点外)完全相同 cprintf()只能用与控制台(或称窗口)下。 printf()函数的默认输出位置是屏幕的右上角顶点坐标,cprintf 参考技术C 其实PRINTF就能解决大多数问题了
以上是关于C语言中cprintf的用法的主要内容,如果未能解决你的问题,请参考以下文章