📄 王大刚--c语言编程宝典--m.htm
字号:
"******************************"; <BR> printf("destination prior to
memmove: %s\n", dest); <BR> memmove(dest, src, 26); <BR>
printf("destination after memmove: %s\n", dest);
<BR> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: memset <BR>功 能: 设置s中的所有字节为ch, s数组的大小由n给定 <BR>用 法: void
*memset(void *s, char ch, unsigned n); <BR>程序例: <BR>
<P>#include <string.h> <BR>#include <stdio.h> <BR>#include
<mem.h> <BR>
<P>int main(void) <BR>{ <BR> char buffer[] = "Hello world\n";
<BR>
<P> printf("Buffer before memset: %s\n", buffer);
<BR> memset(buffer, '*', strlen(buffer) - 1); <BR>
printf("Buffer after memset: %s\n", buffer); <BR> return
0; <BR>} <BR> <BR> <BR>
<P>函数名: mkdir <BR>功 能: 建立一个目录 <BR>用 法: int mkdir(char
*pathname); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <conio.h> <BR>#include
<process.h> <BR>#include <dir.h> <BR>
<P>int main(void) <BR>{ <BR> int status; <BR>
<P> clrscr(); <BR> status = mkdir("asdfjklm");
<BR> (!status) ? (printf("Directory created\n")) :
<BR>
(printf("Unable to create directory\n")); <BR>
<P> getch(); <BR> system("dir"); <BR>
getch(); <BR>
<P> status = rmdir("asdfjklm"); <BR> (!status) ?
(printf("Directory deleted\n")) : <BR> (perror("Unable to delete
directory")); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: mktemp <BR>功 能: 建立唯一的文件名 <BR>用 法: char *mktemp(char
*template); <BR>程序例: <BR>
<P>#include <dir.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> /* fname defines the template for
the <BR> temporary file. */ <BR>
<P> char *fname = "TXXXXXX", *ptr; <BR>
<P> ptr = mktemp(fname); <BR> printf("%s\n",ptr);
<BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: MK_FP <BR>功 能: 设置一个远指针 <BR>用 法: void far
*MK_FP(unsigned seg, unsigned off); <BR>程序例: <BR>
<P>#include <dos.h> <BR>#include <graphics.h> <BR>
<P>int main(void) <BR>{ <BR> int gd, gm, i; <BR>
unsigned int far *screen; <BR>
<P> detectgraph(&gd, &gm); <BR> if (gd ==
HERCMONO) <BR> screen = MK_FP(0xB000,
0); <BR> else <BR> screen
= MK_FP(0xB800, 0); <BR> for (i=0; i<26; i++)
<BR> screen[i] = 0x0700 + ('a' + i);
<BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: modf <BR>功 能: 把数分为指数和尾数 <BR>用 法: double modf(double
value, double *iptr); <BR>程序例: <BR>
<P>#include <math.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> double fraction, integer;
<BR> double number = 100000.567; <BR>
<P> fraction = modf(number, &integer); <BR>
printf("The whole and fractional parts of %lf are %lf and %lf\n",
<BR> number,
integer, fraction); <BR> return 0; <BR>} <BR> <BR>
<BR>
<P>函数名: movedata <BR>功 能: 拷贝字节 <BR>用 法: void movedata(int
segsrc, int offsrc, int segdest, <BR> int offdest, unsigned
numbytes); <BR>程序例: <BR>
<P>#include <mem.h> <BR>
<P>#define MONO_BASE 0xB000 <BR>
<P>/* saves the contents of the monochrome screen in buffer */ <BR>void
save_mono_screen(char near *buffer) <BR>{ <BR>
movedata(MONO_BASE, 0, _DS, (unsigned)buffer, 80*25*2); <BR>} <BR>
<P>int main(void) <BR>{ <BR> char buf[80*25*2];
<BR> save_mono_screen(buf); <BR>} <BR> <BR> <BR>
<P>函数名: moverel <BR>功 能: 将当前位置(CP)移动一相对距离 <BR>用 法: void far
moverel(int dx, int dy); <BR>程序例: <BR>
<P>#include <graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode; <BR>
char msg[80]; <BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, ""); <BR>
<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> } <BR>
<P> /* move the C.P. to location (20, 30) */ <BR>
moveto(20, 30); <BR>
<P> /* plot a pixel at the C.P. */ <BR>
putpixel(getx(), gety(), getmaxcolor()); <BR>
<P> /* create and output a message at (20, 30) */
<BR> sprintf(msg, " (%d, %d)", getx(), gety());
<BR> outtextxy(20, 30, msg); <BR>
<P> /* move to a point a relative distance */ <BR>
/* away from the current value of C.P. */ <BR> moverel(100,
100); <BR>
<P> /* plot a pixel at the C.P. */ <BR>
putpixel(getx(), gety(), getmaxcolor()); <BR>
<P> /* create and output a message at C.P. */ <BR>
sprintf(msg, " (%d, %d)", getx(), gety()); <BR> outtext(msg);
<BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: movetext <BR>功 能: 将屏幕文本从一个矩形区域拷贝到另一个矩形区域 <BR>用 法: int
movetext(int left, int top, int right, int bottom, <BR> int newleft,
int newtop); <BR>程序例: <BR>#include <conio.h> <BR>#include
<string.h> <BR>
<P>int main(void) <BR>{ <BR> char *str = "This is a test
string"; <BR>
<P> clrscr(); <BR> cputs(str); <BR>
getch(); <BR>
<P> movetext(1, 1, strlen(str), 2, 10, 10); <BR>
getch(); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: moveto <BR>功 能: 将CP移到(x, y) <BR>用 法: void far
moveto(int x, int y); <BR>程序例: <BR>
<P>#include <graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> /* request auto detection */
<BR> int gdriver = DETECT, gmode, errorcode; <BR>
char msg[80]; <BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, ""); <BR>
<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> } <BR>
<P> /* move the C.P. to location (20, 30) */ <BR>
moveto(20, 30); <BR>
<P> /* plot a pixel at the C.P. */ <BR>
putpixel(getx(), gety(), getmaxcolor()); <BR>
<P> /* create and output a message at (20, 30) */
<BR> sprintf(msg, " (%d, %d)", getx(), gety());
<BR> outtextxy(20, 30, msg); <BR>
<P> /* move to (100, 100) */ <BR> moveto(100,
100); <BR>
<P> /* plot a pixel at the C.P. */ <BR>
putpixel(getx(), gety(), getmaxcolor()); <BR>
<P> /* create and output a message at C.P. */ <BR>
sprintf(msg, " (%d, %d)", getx(), gety()); <BR> outtext(msg);
<BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: movemem <BR>功 能: 移动一块字节 <BR>用 法: void movemem(void
*source, void *destin, unsigned len); <BR>程序例: <BR>
<P>#include <mem.h> <BR>#include <alloc.h> <BR>#include
<stdio.h> <BR>#include <string.h> <BR>
<P>int main(void) <BR>{ <BR> char *source = "Borland
International"; <BR> char *destination; <BR> int
length; <BR>
<P> length = strlen(source); <BR> destination =
malloc(length + 1); <BR> movmem(source,destination,length);
<BR> printf("%s\n",destination); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: normvideo <BR>功 能: 选择正常亮度字符 <BR>用 法: void
normvideo(void); <BR>程序例: <BR>
<P>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> normvideo(); <BR>
cprintf("NORMAL Intensity Text\r\n"); <BR> return 0; <BR>}
<BR> <BR> <BR>
<P>函数名: nosound <BR>功 能: 关闭PC扬声器 <BR>用 法: void nosound(void);
<BR>程序例: <BR>
<P>/* Emits a 7-Hz tone for 10 seconds. <BR>
<P> True story: 7 Hz is the resonant frequency of
a chicken's skull cavity. <BR> This was determined
empirically in Australia, where a new factory <BR>
generating 7-Hz tones was located too close to a chicken ranch:
<BR> When the factory started up, all the chickens
died. <BR>
<P> Your PC may not be able to emit a 7-Hz tone.
<BR>*/ <BR>
<P>int main(void) <BR>{ <BR> sound(7); <BR>
delay(10000); <BR> nosound(); <BR>} <BR> <BR>
<HR width="94%" color=#ee9b73 SIZE=1>
</TD>
<TD class=tt3 vAlign=bottom width="8%" bgColor=#e0e0e0><STRONG><A
href="http://www.hjflying.8u8.com/cl/032.htm">后一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/030.htm">前一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/index.html">回目录</A><BR><A
href="http://www.hjflying.8u8.com/index.htm">回首页</A><BR></STRONG></TD></TR></TBODY></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -