📄 fc.htm
字号:
<HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"> <META NAME="Author" CONTENT="wdg"> <META NAME="GENERATOR" CONTENT="Mozilla/4.03 [en] (Win95; I) [Netscape]"> <TITLE>fc</TITLE></HEAD><BODY> <P>函数名: cabs<BR>功 能: 计算复数的绝对值<BR>用 法: double cabs(struct complex z);<BR>程序例:<P>#include <stdio.h><BR>#include <math.h><P>int main(void)<BR>{<BR> struct complex z;<BR> double val;<P> z.x = 2.0;<BR> z.y = 1.0;<BR> val = cabs(z);<P> printf("The absolute value of %.2lfi %.2lfj is %.2lf",z.x, z.y, val);<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: calloc<BR>功 能: 分配主存储器<BR>用 法: void *calloc(size_t nelem, size_t elsize);<BR>程序例:<P>#include <stdio.h><BR>#include <alloc.h><P>int main(void)<BR>{<BR> char *str = NULL;<P> /* allocate memory for string */<BR> str = calloc(10, sizeof(char));<P> /* copy "Hello" into string */<BR> strcpy(str, "Hello");<P> /* display string */<BR> printf("String is %s\n", str);<P> /* free memory */<BR> free(str);<P> return 0;<BR>}<BR> <BR> <BR> <P>函数名: ceil<BR>功 能: 向上舍入<BR>用 法: double ceil(double x);<BR>程序例:<P>#include <math.h><BR>#include <stdio.h><P>int main(void)<BR>{<BR> double number = 123.54;<BR> double down, up;<P> down = floor(number);<BR> up = ceil(number);<P> printf("original number %5.2lf\n",number);<BR> printf("number rounded down %5.2lf\n", down);<BR> printf("number rounded up %5.2lf\n", up);<P> return 0;<BR>}<BR> <BR> <BR> <P>函数名: cgets<BR>功 能: 从控制台读字符串<BR>用 法: char *cgets(char *str);<BR>程序例:<P>#include <stdio.h><BR>#include <conio.h><P>int main(void)<BR>{<BR> char buffer[83];<BR> char *p;<P> /* There's space for 80 characters plus the NULL terminator*/<BR> buffer[0] = 81;<P> printf("Input some chars:");<BR> p = cgets(buffer);<BR> printf("\ncgets read %d characters: \"%s\"\n", buffer[1],p);<BR> printf("The returned pointer is %p, buffer[0] is at %p\n",p, &buffer);<P> /* Leave room for 5 characters plus the NULL terminator*/<BR> buffer[0] = 6;<P> printf("Input some chars:");<BR> p = cgets(buffer);<BR> printf("\ncgets read %d characters: \"%s\"\n", buffer[1],p);<BR> printf("The returned pointer is %p, buffer[0] is at %p\n",p, &buffer);<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: chdir<BR>功 能: 改变工作目录<BR>用 法: int chdir(const char *path);<BR>程序例:<P>#include <stdio.h><BR>#include <stdlib.h><BR>#include <dir.h><P>char old_dir[MAXDIR];<BR>char new_dir[MAXDIR];<P>int main(void)<BR>{<BR> if (getcurdir(0, old_dir))<BR> {<BR> perror("getcurdir()");<BR> exit(1);<BR> }<BR> printf("Current directory is: \\%s\n", old_dir);<P> if (chdir("\\"))<BR> {<BR> perror("chdir()");<BR> exit(1);<BR> }<P> if (getcurdir(0, new_dir))<BR> {<BR> perror("getcurdir()");<BR> exit(1);<BR> }<BR> printf("Current directory is now: \\%s\n", new_dir);<P> printf("\nChanging back to orignal directory: \\%s\n",old_dir);<BR> if (chdir(old_dir))<BR> {<BR> perror("chdir()");<BR> exit(1);<BR> }<P> return 0;<BR>}<BR> <BR> <P>函数名: _chmod, chmod<BR>功 能: 改变文件的访问方式<BR>用 法: int chmod(const char *filename, int permiss);<BR>程序例:<P>#include <sys\stat.h><BR>#include <stdio.h><BR>#include <io.h><P>void make_read_only(char *filename);<P>int main(void)<BR>{<BR> make_read_only("NOTEXIST.FIL");<BR> make_read_only("MYFILE.FIL");<BR> return 0;<BR>}<P>void make_read_only(char *filename)<BR>{<BR> int stat;<P> stat = chmod(filename, S_IREAD);<BR> if (stat)<BR> printf("Couldn't make %s read-only\n",filename);<BR> else<BR> printf("Made %s read-only\n", filename);<BR>}<BR> <BR> <BR> <P>函数名: chsize<BR>功 能: 改变文件大小<BR>用 法: int chsize(int handle, long size);<BR>程序例:<P>#include <string.h><BR>#include <fcntl.h><BR>#include <io.h><P>int main(void)<BR>{<BR> int handle;<BR> char buf[11] = "0123456789";<P> /* create text file containing 10 bytes */<BR> handle = open("DUMMY.FIL", O_CREAT);<BR> write(handle, buf, strlen(buf));<P> /* truncate the file to 5 bytes in size */<BR> chsize(handle, 5);<P> /* close the file */<BR> close(handle);<BR> return 0;<BR>}<BR> <BR> <P>函数名: circle<BR>功 能: 在给定半径以(x, y)为圆心画圆<BR>用 法: void far circle(int x, int y, int radius);<BR>程序例:<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><P>int main(void)<BR>{<BR> /* request auto detection */<BR> int gdriver = DETECT, gmode, errorcode;<BR> int midx, midy;<BR> int radius = 100;<P> /* initialize graphics and local variables */<BR> initgraph(&gdriver, &gmode, "");<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 errorcode */<BR> }<P> midx = getmaxx() / 2;<BR> midy = getmaxy() / 2;<BR> setcolor(getmaxcolor());<P> /* draw the circle */<BR> circle(midx, midy, radius);<P> /* clean up */<BR> getch();<BR> closegraph();<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: cleardevice<BR>功 能: 清除图形屏幕<BR>用 法: void far cleardevice(void);<BR>程序例:<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><P>int main(void)<BR>{<BR> /* request auto detection */<BR> int gdriver = DETECT, gmode, errorcode;<BR> int midx, midy;<P> /* initialize graphics and local variables */<BR> initgraph(&gdriver, &gmode, "");<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 errorcode */<BR> }<P> midx = getmaxx() / 2;<BR> midy = getmaxy() / 2;<BR> setcolor(getmaxcolor());<P> /* for centering screen messages */<BR> settextjustify(CENTER_TEXT, CENTER_TEXT);<P> /* output a message to the screen */<BR> outtextxy(midx, midy, "press any key to clear the screen:");<P> /* wait for a key */<BR> getch();<P> /* clear the screen */<BR> cleardevice();<P> /* output another message */<BR> outtextxy(midx, midy, "press any key to quit:");<P> /* clean up */<BR> getch();<BR> closegraph();<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: clearerr<BR>功 能: 复位错误标志<BR>用 法:void clearerr(FILE *stream);<BR>程序例:<P>#include <stdio.h><P>int main(void)<BR>{<BR> FILE *fp;<BR> char ch;<P> /* open a file for writing */<BR> fp = fopen("DUMMY.FIL", "w");<P> /* force an error condition by attempting to read */<BR> ch = fgetc(fp);<BR> printf("%c\n",ch);<P> if (ferror(fp))<BR> {<BR> /* display an error message */<BR> printf("Error reading from DUMMY.FIL\n");<P> /* reset the error and EOF indicators*/<BR> clearerr(fp);<BR> }<P> fclose(fp);<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: clearviewport<BR>功 能: 清除图形视区<BR>用 法: void far clearviewport(void);<BR>程序例:<P>#include <graphics.h><BR>#include <stdlib.h><BR>#include <stdio.h><BR>#include <conio.h><P>#define CLIP_ON 1 /* activates clipping in viewport */<P>int main(void)<BR>{<BR> /* request auto detection */<BR> int gdriver = DETECT, gmode, errorcode;<BR> int ht;<P> /* initialize graphics and local variables */<BR> initgraph(&gdriver, &gmode, "");<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 errorcode */<BR> }<P> setcolor(getmaxcolor());<BR> ht = textheight("W");<P> /* message in default full-screen viewport */<BR> outtextxy(0, 0, "* <-- (0, 0) in default viewport");<P> /* create a smaller viewport */<BR> setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON);<P> /* display some messages */<BR> outtextxy(0, 0, "* <-- (0, 0) in smaller viewport");<BR> outtextxy(0, 2*ht, "Press any key to clear viewport:");<P> /* wait for a key */<BR> getch();<P> /* clear the viewport */<BR> clearviewport();<P> /* output another message */<BR> outtextxy(0, 0, "Press any key to quit:");<P> /* clean up */<BR> getch();<BR> closegraph();<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: _close, close<BR>功 能: 关闭文件句柄<BR>用 法: int close(int handle);<BR>程序例:<P>#include <string.h><BR>#include <stdio.h><BR>#include <fcntl.h><BR>#include <io.h><P>main()<BR>{<BR> int handle;<BR> char buf[11] = "0123456789";<P> /* create a file containing 10 bytes */<BR> handle = open("NEW.FIL", O_CREAT);<BR> if (handle > -1)<BR> {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -