⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p.htm

📁 C语言函数库,包含所有的C语言函数
💻 HTM
📖 第 1 页 / 共 2 页
字号:
{ 
char msg[] = "Hello world\n"; 
int i = 0; </PRE>
<PRE>while (msg[i]) 
putc(msg[i++], stdout); 
return 0; 
} 

</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> putch </font>
功 能: 输出字符到控制台 
用 法: int putch(int ch); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>int main(void) 
{ 
char ch = 0; </PRE>
<PRE>printf(&quot;Input a string:&quot;); 
while ((ch != '\r')) 
{ 
ch = getch(); 
putch(ch); 
} 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">putchar </font>
功 能: 在stdout上输出字符 
用 法: int putchar(int ch); 
程序例: </PRE>
<PRE>#include </PRE>
<PRE>/* define some box-drawing characters */ 
#define LEFT_TOP 0xDA 
#define RIGHT_TOP 0xBF 
#define HORIZ 0xC4 
#define VERT 0xB3 
#define LEFT_BOT 0xC0 
#define RIGHT_BOT 0xD9 </PRE>
<PRE>int main(void) 
{ 
char i, j; </PRE>
<PRE>/* draw the top of the box */ 
putchar(LEFT_TOP); 
for (i=0; i&lt;10; i++) 
putchar(HORIZ); 
putchar(RIGHT_TOP); 
putchar('\n'); </PRE>
<PRE>/* draw the middle */ 
for (i=0; i&lt;4; i++) 
{ 
putchar(VERT); 
for (j=0; j&lt;10; j++) 
putchar(' '); 
putchar(VERT); 
putchar('\n'); 
} </PRE>
<PRE>/* draw the bottom */ 
putchar(LEFT_BOT); 
for (i=0; i&lt;10; i++) 
putchar(HORIZ); 
putchar(RIGHT_BOT); 
putchar('\n'); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> putenv </font>
功 能: 把字符串加到当前环境中 
用 法: int putenv(char *envvar); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include 
#include </PRE>
<PRE>int main(void) 
{ 
char *path, *ptr; 
int i = 0; </PRE>
<PRE>/* get the current path environment */ 
ptr = getenv(&quot;PATH&quot;); </PRE>
<PRE>/* set up new path */ 
path = malloc(strlen(ptr)+15); 
strcpy(path,&quot;PATH=&quot;); 
strcat(path,ptr); 
strcat(path,&quot;;c:\\temp&quot;); </PRE>
<PRE>/* replace the current path and display current environment */ 
putenv(path); 
while (environ[i]) 
printf(&quot;%s\n&quot;,environ[i++]); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名:<font size="5" color="#FF0000"> putimage </font>
功 能: 在屏幕上输出一个位图 
用 法: void far putimage(int x, int y, void far *bitmap, int op); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include </PRE>
<PRE>#define ARROW_SIZE 10 </PRE>
<PRE>void draw_arrow(int x, int y); </PRE>
<PRE>int main(void) 
{ 
/* request autodetection */ 
int gdriver = DETECT, gmode, errorcode; 
void *arrow; 
int x, y, maxx; 
unsigned int size; </PRE>
<PRE>/* initialize graphics and local variables */ 
initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </PRE>
<PRE>/* read result of initialization */ 
errorcode = graphresult(); 
if (errorcode != grOk) /* an error occurred */ 
{ 
printf(&quot;Graphics error: %s\n&quot;, grapherrormsg(errorcode)); 
printf(&quot;Press any key to halt:&quot;); 
getch(); 
exit(1); /* terminate with an error code */ 
} </PRE>
<PRE>maxx = getmaxx(); 
x = 0; 
y = getmaxy() / 2; </PRE>
<PRE>/* draw the image to be grabbed */ 
draw_arrow(x, y); </PRE>
<PRE>/* calculate the size of the image */ 
size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </PRE>
<PRE>/* allocate memory to hold the image */ 
arrow = malloc(size); </PRE>
<PRE>/* grab the image */ 
getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </PRE>
<PRE>/* repeat until a key is pressed */ 
while (!kbhit()) 
{ 
/* erase old image */ 
putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </PRE>
<PRE>x += ARROW_SIZE; 
if (x &gt;= maxx) 
x = 0; </PRE>
<PRE>/* plot new image */ 
putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); 
} </PRE>
<PRE>/* clean up */ 
free(arrow); 
closegraph(); 
return 0; 
} </PRE>
<PRE>void draw_arrow(int x, int y) 
{ 
/* draw an arrow on the screen */ 
moveto(x, y); 
linerel(4*ARROW_SIZE, 0); 
linerel(-2*ARROW_SIZE, -1*ARROW_SIZE); 
linerel(0, 2*ARROW_SIZE); 
linerel(2*ARROW_SIZE, -1*ARROW_SIZE); 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">putpixel </font>
功 能: 在指定位置画一像素 
用 法: void far putpixel (int x, int y, int pixelcolor); 
程序例: </PRE>
<PRE>#include 
#include 
#include 
#include 
#include </PRE>
<PRE>#define PIXEL_COUNT 1000 
#define DELAY_TIME 100 /* in milliseconds */ </PRE>
<PRE>int main(void) 
{ 
/* request autodetection */ 
int gdriver = DETECT, gmode, errorcode; 
int i, x, y, color, maxx, maxy, maxcolor, seed; </PRE>
<PRE>/* initialize graphics and local variables */ 
initgraph(&amp;gdriver, &amp;gmode, &quot;&quot;); </PRE>
<PRE>/* read result of initialization */ 
errorcode = graphresult(); 
if (errorcode != grOk) /* an error occurred */ 
{ 
printf(&quot;Graphics error: %s\n&quot;, grapherrormsg(errorcode)); 
printf(&quot;Press any key to halt:&quot;); 
getch(); 
exit(1); /* terminate with an error code */ 
} </PRE>
<PRE>maxx = getmaxx() + 1; 
maxy = getmaxy() + 1; 
maxcolor = getmaxcolor() + 1; </PRE>
<PRE>while (!kbhit()) 
{ 
/* seed the random number generator */ 
seed = random(32767); 
srand(seed); 
for (i=0; i { 
x = random(maxx); 
y = random(maxy); 
color = random(maxcolor); 
putpixel(x, y, color); 
} </PRE>
<PRE>delay(DELAY_TIME); 
srand(seed); 
for (i=0; i { 
x = random(maxx); 
y = random(maxy); 
color = random(maxcolor); 
if (color == getpixel(x, y)) 
putpixel(x, y, 0); 
} 
} </PRE>
<PRE>/* clean up */ 
getch(); 
closegraph(); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">puts </font>
功 能: 送一字符串到流中 
用 法: int puts(char *string); 
程序例: </PRE>
<PRE>#include 
int main(void) 
{ 
char string[] = &quot;This is an example output string\n&quot;; </PRE>
<PRE>puts(string); 
return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">puttext</font> 
功 能: 将文本从存储区拷贝到屏幕 
用 法: int puttext(int left, int top, int right, int bottom, void *source); 
程序例: </PRE>
<PRE>#include 
int main(void) 
{ 
char buffer[512]; </PRE>
<PRE>/* put some text to the console */ 
clrscr(); 
gotoxy(20, 12); 
cprintf(&quot;This is a test. Press any key to continue ...&quot;); 
getch(); </PRE>
<PRE>/* grab screen contents */ 
gettext(20, 12, 36, 21,buffer); 
clrscr(); </PRE>
<PRE>/* put selected characters back to the screen */ 
gotoxy(20, 12); 
puttext(20, 12, 36, 21, buffer); 
getch(); </PRE>
<PRE>return 0; 
} 

</PRE>
<PRE>函数名: <font size="5" color="#FF0000">putw </font>
功 能: 把一字符或字送到流中 
用 法: int putw(int w, FILE *stream); 
程序例: </PRE>
<PRE>#include 
#include </PRE>
<PRE>#define FNAME &quot;test.$$$&quot; </PRE>
<PRE>int main(void) 
{ 
FILE *fp; 
int word; </PRE>
<PRE>/* place the word in a file */ 
fp = fopen(FNAME, &quot;wb&quot;); 
if (fp == NULL) 
{ 
printf(&quot;Error opening file %s\n&quot;, FNAME); 
exit(1); 
} </PRE>
<PRE>word = 94; 
putw(word,fp); 
if (ferror(fp)) 
printf(&quot;Error writing to file\n&quot;); 
else 
printf(&quot;Successful write\n&quot;); 
fclose(fp); </PRE>
<PRE>/* reopen the file */ 
fp = fopen(FNAME, &quot;rb&quot;); 
if (fp == NULL) 
{ 
printf(&quot;Error opening file %s\n&quot;, FNAME); 
exit(1); 
} </PRE>
<PRE>/* extract the word */ 
word = getw(fp); 
if (ferror(fp)) 
printf(&quot;Error reading file\n&quot;); 
else 
printf(&quot;Successful read: word = %d\n&quot;, word); </PRE>
<PRE>/* clean up */ 
fclose(fp); 
unlink(FNAME); </PRE>
<PRE>return 0; 
} 



</PRE>

<PRE><font size="5"><a href="a.htm">A</a> <a href="b.htm">B</a> <a href="c.htm">C</a> <a href="d.htm">D</a> <a href="e.htm">E</a> <a href="f.htm">F</a> <a href="g.htm">G</a> <a href="h.htm">H</a> <a href="i.htm">I</a> <a href="k.htm">K</a> <a href="l.htm">L</a> <a href="m.htm">M</a> <a href="n.htm">N</a> <a href="o.htm">O</a> <a href="p.htm">P</a> <a href="q.htm">Q</a> <a href="r.htm">R</a> <a href="s.htm">S</a> <a href="t.htm">T</a> <a href="u.htm">U</a> <a href="v.htm">V</a> <a href="w.htm">W</a> </font></PRE>

<PRE> </PRE>
<PRE>
</PRE>
<pre>资料收集:beck Copyright 2004 张求熙, All Rights Reserved</pre>
<pre><a href="mailto:Email:qiuxi1984@126.com">Email:qiuxi1984@126.com</a>     QQ:35540948 </pre>
<PRE> </PRE>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -