📄 fp.htm
字号:
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<p>#define ARROW_SIZE 10 </p>
<p>void draw_arrow(int x, int y); </p>
<p>int main(void) <br>
{ <br>
/* request autodetection */ <br>
int gdriver = DETECT, gmode, errorcode; <br>
void *arrow; <br>
int x, y, maxx; <br>
unsigned int size; </p>
<p> /* initialize graphics and local
variables */ <br>
initgraph(&gdriver, &gmode,
""); </p>
<p> /* read result of initialization */ <br>
errorcode = graphresult(); <br>
if (errorcode != grOk) /* an error
occurred */ <br>
{ <br>
printf("Graphics
error: %s\n", grapherrormsg(errorcode)); <br>
printf("Press any key
to halt:"); <br>
getch(); <br>
exit(1); /* terminate with
an error code */ <br>
} </p>
<p> maxx = getmaxx(); <br>
x = 0; <br>
y = getmaxy() / 2; </p>
<p> /* draw the image to be grabbed */ <br>
draw_arrow(x, y); </p>
<p> /* calculate the size of the image */ <br>
size = imagesize(x, y-ARROW_SIZE,
x+(4*ARROW_SIZE), y+ARROW_SIZE); </p>
<p> /* allocate memory to hold the image */ <br>
arrow = malloc(size); </p>
<p> /* grab the image */ <br>
getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE),
y+ARROW_SIZE, arrow); </p>
<p> /* repeat until a key is pressed */ <br>
while (!kbhit()) <br>
{ <br>
/* erase old image */ <br>
putimage(x, y-ARROW_SIZE,
arrow, XOR_PUT); </p>
<p> x += ARROW_SIZE; <br>
if (x >= maxx) <br>
x
= 0; </p>
<p> /* plot new image */ <br>
putimage(x, y-ARROW_SIZE,
arrow, XOR_PUT); <br>
} </p>
<p> /* clean up */ <br>
free(arrow); <br>
closegraph(); <br>
return 0; <br>
} </p>
<p>void draw_arrow(int x, int y) <br>
{ <br>
/* draw an arrow on the screen */ <br>
moveto(x, y); <br>
linerel(4*ARROW_SIZE, 0); <br>
linerel(-2*ARROW_SIZE, -1*ARROW_SIZE); <br>
linerel(0, 2*ARROW_SIZE); <br>
linerel(2*ARROW_SIZE, -1*ARROW_SIZE); <br>
} <br>
<br>
</p>
<p>函数名: putpixel <br>
功 能: 在指定位置画一像素 <br>
用 法: void far putpixel (int x, int y, int
pixelcolor); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> <br>
#include <dos.h> </p>
<p>#define PIXEL_COUNT 1000 <br>
#define DELAY_TIME 100 /* in milliseconds */ </p>
<p>int main(void) <br>
{ <br>
/* request autodetection */ <br>
int gdriver = DETECT, gmode, errorcode; <br>
int i, x, y, color, maxx, maxy, maxcolor,
seed; </p>
<p> /* initialize graphics and local
variables */ <br>
initgraph(&gdriver, &gmode,
""); </p>
<p> /* read result of initialization */ <br>
errorcode = graphresult(); <br>
if (errorcode != grOk) /* an error
occurred */ <br>
{ <br>
printf("Graphics
error: %s\n", grapherrormsg(errorcode)); <br>
printf("Press any key
to halt:"); <br>
getch(); <br>
exit(1); /* terminate with
an error code */ <br>
} </p>
<p> maxx = getmaxx() + 1; <br>
maxy = getmaxy() + 1; <br>
maxcolor = getmaxcolor() + 1; </p>
<p> while (!kbhit()) <br>
{ <br>
/* seed the random number
generator */ <br>
seed = random(32767); <br>
srand(seed); <br>
for (i=0;
i<PIXEL_COUNT; i++) <br>
{ <br>
x = random(maxx); <br>
y =
random(maxy); <br>
color =
random(maxcolor); <br>
putpixel(x, y, color); <br>
} </p>
<p> delay(DELAY_TIME); <br>
srand(seed); <br>
for (i=0;
i<PIXEL_COUNT; i++) <br>
{ <br>
x = random(maxx); <br>
y = random(maxy); <br>
color = random(maxcolor); <br>
if (color == getpixel(x, y)) <br>
putpixel(x, y, 0); <br>
} <br>
} </p>
<p> /* clean up */ <br>
getch(); <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: puts <br>
功 能: 送一字符串到流中 <br>
用 法: int puts(char *string); <br>
程序例: </p>
<p>#include <stdio.h> <br>
int main(void) <br>
{ <br>
char string[] = "This is an example
output string\n"; </p>
<p> puts(string); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: puttext <br>
功 能: 将文本从存储区拷贝到屏幕 <br>
用 法: int puttext(int left, int top, int right,
int bottom, void *source); <br>
程序例: </p>
<p>#include <conio.h> <br>
int main(void) <br>
{ <br>
char buffer[512]; </p>
<p> /* put some text to the console */ <br>
clrscr(); <br>
gotoxy(20, 12); <br>
cprintf("This is a test. Press
any key to continue ..."); <br>
getch(); </p>
<p> /* grab screen contents */ <br>
gettext(20, 12, 36, 21,buffer); <br>
clrscr(); </p>
<p> /* put selected characters back to the
screen */ <br>
gotoxy(20, 12); <br>
puttext(20, 12, 36, 21, buffer); <br>
getch(); </p>
<p> return 0; <br>
} <br>
<br>
</p>
<p>函数名: putw <br>
功 能: 把一字符或字送到流中 <br>
用 法: int putw(int w, FILE *stream); <br>
程序例: </p>
<p>#include <stdio.h> <br>
#include <stdlib.h> </p>
<p>#define FNAME "test.$$$" </p>
<p>int main(void) <br>
{ <br>
FILE *fp; <br>
int word; </p>
<p> /* place the word in a file */ <br>
fp = fopen(FNAME, "wb"); <br>
if (fp == NULL) <br>
{ <br>
printf("Error opening
file %s\n", FNAME); <br>
exit(1); <br>
} </p>
<p> word = 94; <br>
putw(word,fp); <br>
if (ferror(fp)) <br>
printf("Error
writing to file\n"); <br>
else <br>
printf("Successful write\n"); <br>
fclose(fp); </p>
<p> /* reopen the file */ <br>
fp = fopen(FNAME, "rb"); <br>
if (fp == NULL) <br>
{ <br>
printf("Error opening
file %s\n", FNAME); <br>
exit(1); <br>
} </p>
<p> /* extract the word */ <br>
word = getw(fp); <br>
if (ferror(fp)) <br>
printf("Error
reading file\n"); <br>
else <br>
printf("Successful read: word = %d\n", word); </p>
<p> /* clean up */ <br>
fclose(fp); <br>
unlink(FNAME); </p>
<p> return 0; <br>
} <br>
</p>
</td>
</tr>
</table>
</center></div><div align="center"><center>
<table border="0" cellspacing="1" width="640">
<tr>
<td class="p9" height="60"> <script>document.write("<p><a href=\"http://view.gznet.com/cgi-bin/rl_views.cgi?UID=10013421\" target=sxrl>");
document.write("<img src=\"http://refer.gznet.com/cgi-bin/rl_refer2.cgi?UID=10013421&refer="+escape(top.document.referrer)+"\" width=1 height=1 border=0 alt=\" \">");
document.write("</a>");
</script></td>
</tr>
</table>
</center></div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -