📄 c语言函数大全(待继续研究).mht
字号:
=D5=FB=C0=ED =B7=A2=B2=BC=CA=B1=BC=E4=A3=BA2006-3-7=20
16:31:56 =B7=A2=B2=BC=C8=CB=A3=BAwongrs</TD></TR>
<SCRIPT language=3Djavascript>
var newasp_fontsize=3D9;
var newasp_lineheight=3D12;
</SCRIPT>
<TR>
<TD><BR>
<SCRIPT type=3Dtext/javascript><!--
google_ad_client =3D "pub-3216291423111766";
google_ad_width =3D 336;
google_ad_height =3D 280;
google_ad_format =3D "336x280_as";
google_ad_type =3D "text";
google_ad_channel =3D "";
//--></SCRIPT>
<SCRIPT =
src=3D"http://pagead2.googlesyndication.com/pagead/show_ads.js"=20
type=3Dtext/javascript>
</SCRIPT>
<P>=BA=AF=CA=FD=C3=FB: cabs <BR>=B9=A6 =C4=DC: =
=BC=C6=CB=E3=B8=B4=CA=FD=B5=C4=BE=F8=B6=D4=D6=B5 <BR>=D3=C3 =B7=A8: =
double cabs(struct complex z);=20
<BR>=B3=CC=D0=F2=C0=FD: </P>
<P>#include <BR>#include </P>
<P>int main(void) <BR>{ <BR>struct complex z; <BR>double val; =
</P>
<P>z.x =3D 2.0; <BR>z.y =3D 1.0; <BR>val =3D cabs(z); </P>
<P>printf("The absolute value of %.2lfi %.2lfj is %.2lf", z.x, =
z.y,=20
val); <BR>return 0; <BR>} <BR><BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: calloc <BR>=B9=A6 =C4=DC: =
=B7=D6=C5=E4=D6=F7=B4=E6=B4=A2=C6=F7 <BR>=D3=C3 =B7=A8: void =
*calloc(size_t nelem,=20
size_t elsize); <BR>=B3=CC=D0=F2=C0=FD: </P>
<P>#include <BR>#include </P>
<P>int main(void) <BR>{ <BR>char *str =3D NULL; </P>
<P>/* allocate memory for string */ <BR>str =3D calloc(10, =
sizeof(char));=20
</P>
<P>/* copy "Hello" into string */ <BR>strcpy(str, "Hello"); </P>
<P>/* display string */ <BR>printf("String is %s\n", str); </P>
<P>/* free memory */ <BR>free(str); </P>
<P>return 0; <BR>} <BR><BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: ceil <BR>=B9=A6 =C4=DC: =
=CF=F2=C9=CF=C9=E1=C8=EB <BR>=D3=C3 =B7=A8: double ceil(double x); =
<BR>=B3=CC=D0=F2=C0=FD: </P>
<P>#include <BR>#include </P>
<P>int main(void) <BR>{ <BR>double number =3D 123.54; <BR>double =
down, up;=20
</P>
<P>down =3D floor(number); <BR>up =3D ceil(number); </P>
<P>printf("original number %5.2lf\n", number); =
<BR>printf("number=20
rounded down %5.2lf\n", down); <BR>printf("number rounded up =
%5.2lf\n",=20
up); </P>
<P>return 0; <BR>} <BR><BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: cgets <BR>=B9=A6 =C4=DC: =
=B4=D3=BF=D8=D6=C6=CC=A8=B6=C1=D7=D6=B7=FB=B4=AE <BR>=D3=C3 =B7=A8: char =
*cgets(char *str);=20
<BR>=B3=CC=D0=F2=C0=FD: </P>
<P>#include <BR>#include </P>
<P>int main(void) <BR>{ <BR>char buffer[83]; <BR>char *p; </P>
<P>/* There's space for 80 characters plus the NULL terminator =
*/=20
<BR>buffer[0] =3D 81; </P>
<P>printf("Input some chars:"); <BR>p =3D cgets(buffer);=20
<BR>printf("\ncgets read %d characters: \"%s\"\n", buffer[1], =
p);=20
<BR>printf("The returned pointer is %p, buffer[0] is at %p\n", =
p,=20
&buffer); </P>
<P>/* Leave room for 5 characters plus the NULL terminator */=20
<BR>buffer[0] =3D 6; </P>
<P>printf("Input some chars:"); <BR>p =3D cgets(buffer);=20
<BR>printf("\ncgets read %d characters: \"%s\"\n", buffer[1], =
p);=20
<BR>printf("The returned pointer is %p, buffer[0] is at %p\n", =
p,=20
&buffer); <BR>return 0; <BR>} <BR><BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: chdir <BR>=B9=A6 =C4=DC: =
=B8=C4=B1=E4=B9=A4=D7=F7=C4=BF=C2=BC <BR>=D3=C3 =B7=A8: int chdir(const =
char *path);=20
<BR>=B3=CC=D0=F2=C0=FD: </P>
<P>#include <BR>#include <BR>#include </P>
<P>char old_dir[MAXDIR]; <BR>char new_dir[MAXDIR]; </P>
<P>int main(void) <BR>{ <BR>if (getcurdir(0, old_dir)) <BR>{=20
<BR>perror("getcurdir()"); <BR>exit(1); <BR>} =
<BR>printf("Current=20
directory is: \\%s\n", old_dir); </P>
<P>if (chdir("\\")) <BR>{ <BR>perror("chdir()"); <BR>exit(1); =
<BR>} </P>
<P>if (getcurdir(0, new_dir)) <BR>{ <BR>perror("getcurdir()");=20
<BR>exit(1); <BR>} <BR>printf("Current directory is now: =
\\%s\n",=20
new_dir); </P>
<P>printf("\nChanging back to orignal directory: \\%s\n", =
old_dir);=20
<BR>if (chdir(old_dir)) <BR>{ <BR>perror("chdir()"); =
<BR>exit(1); <BR>}=20
</P>
<P>return 0; <BR>} <BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: _chmod, chmod <BR>=B9=A6 =C4=DC: =
=B8=C4=B1=E4=CE=C4=BC=FE=B5=C4=B7=C3=CE=CA=B7=BD=CA=BD <BR>=D3=C3 =
=B7=A8: int chmod(const char=20
*filename, int permiss); <BR>=B3=CC=D0=F2=C0=FD: </P>
<P>#include <BR>#include <BR>#include </P>
<P>void make_read_only(char *filename); </P>
<P>int main(void) <BR>{ <BR>make_read_only("NOTEXIST.FIL");=20
<BR>make_read_only("MYFILE.FIL"); <BR>return 0; <BR>} </P>
<P>void make_read_only(char *filename) <BR>{ <BR>int stat; </P>
<P>stat =3D chmod(filename, S_IREAD); <BR>if (stat) =
<BR>printf("Couldn't=20
make %s read-only\n", filename); <BR>else <BR>printf("Made %s=20
read-only\n", filename); <BR>} <BR><BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: chsize <BR>=B9=A6 =C4=DC: =
=B8=C4=B1=E4=CE=C4=BC=FE=B4=F3=D0=A1 <BR>=D3=C3 =B7=A8: int chsize(int =
handle, long=20
size); <BR>=B3=CC=D0=F2=C0=FD: </P>
<P>#include <BR>#include <BR>#include </P>
<P>int main(void) <BR>{ <BR>int handle; <BR>char buf[11] =3D =
"0123456789";=20
</P>
<P>/* create text file containing 10 bytes */ <BR>handle =3D=20
open("DUMMY.FIL", O_CREAT); <BR>write(handle, buf, strlen(buf)); =
</P>
<P>/* truncate the file to 5 bytes in size */ <BR>chsize(handle, =
5);=20
</P>
<P>/* close the file */ <BR>close(handle); <BR>return 0; <BR>}=20
<BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: circle <BR>=B9=A6 =C4=DC: =
=D4=DA=B8=F8=B6=A8=B0=EB=BE=B6=D2=D4(x, y)=CE=AA=D4=B2=D0=C4=BB=AD=D4=B2 =
<BR>=D3=C3 =B7=A8: void far circle(int=20
x, int y, int radius); <BR>=B3=CC=D0=F2=C0=FD: </P>
<P>#include <BR>#include <BR>#include <BR>#include </P>
<P>int main(void) <BR>{ <BR>/* request auto detection */ <BR>int =
gdriver=20
=3D DETECT, gmode, errorcode; <BR>int midx, midy; <BR>int radius =
=3D 100;=20
</P>
<P>/* initialize graphics and local variables */=20
<BR>initgraph(&gdriver, &gmode, ""); </P>
<P>/* read result of initialization */ <BR>errorcode =3D =
graphresult();=20
<BR>if (errorcode !=3D grOk) /* an error occurred */ <BR>{=20
<BR>printf("Graphics error: %s\n", grapherrormsg(errorcode));=20
<BR>printf("Press any key to halt:"); <BR>getch(); <BR>exit(1); =
/*=20
terminate with an error code */ <BR>} </P>
<P>midx =3D getmaxx() / 2; <BR>midy =3D getmaxy() / 2;=20
<BR>setcolor(getmaxcolor()); </P>
<P>/* draw the circle */ <BR>circle(midx, midy, radius); </P>
<P>/* clean up */ <BR>getch(); <BR>closegraph(); <BR>return 0; =
<BR>}=20
<BR><BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: cleardevice <BR>=B9=A6 =C4=DC: =
=C7=E5=B3=FD=CD=BC=D0=CE=C6=C1=C4=BB <BR>=D3=C3 =B7=A8: void far =
cleardevice(void);=20
<BR>=B3=CC=D0=F2=C0=FD: </P>
<P>#include <BR>#include <BR>#include <BR>#include </P>
<P>int main(void) <BR>{ <BR>/* request auto detection */ <BR>int =
gdriver=20
=3D DETECT, gmode, errorcode; <BR>int midx, midy; </P>
<P>/* initialize graphics and local variables */=20
<BR>initgraph(&gdriver, &gmode, ""); </P>
<P>/* read result of initialization */ <BR>errorcode =3D =
graphresult();=20
<BR>if (errorcode !=3D grOk) /* an error occurred */ <BR>{=20
<BR>printf("Graphics error: %s\n", grapherrormsg(errorcode));=20
<BR>printf("Press any key to halt:"); <BR>getch(); <BR>exit(1); =
/*=20
terminate with an error code */ <BR>} </P>
<P>midx =3D getmaxx() / 2; <BR>midy =3D getmaxy() / 2;=20
<BR>setcolor(getmaxcolor()); </P>
<P>/* for centering screen messages */ =
<BR>settextjustify(CENTER_TEXT,=20
CENTER_TEXT); </P>
<P>/* output a message to the screen */ <BR>outtextxy(midx, =
midy, "press=20
any key to clear the screen:"); </P>
<P>/* wait for a key */ <BR>getch(); </P>
<P>/* clear the screen */ <BR>cleardevice(); </P>
<P>/* output another message */ <BR>outtextxy(midx, midy, "press =
any key=20
to quit:"); </P>
<P>/* clean up */ <BR>getch(); <BR>closegraph(); <BR>return 0; =
<BR>}=20
<BR><BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: clearerr <BR>=B9=A6 =C4=DC: =
=B8=B4=CE=BB=B4=ED=CE=F3=B1=EA=D6=BE <BR>=D3=C3 =B7=A8:void =
clearerr(FILE *stream);=20
<BR>=B3=CC=D0=F2=C0=FD: </P>
<P>#include </P>
<P>int main(void) <BR>{ <BR>FILE *fp; <BR>char ch; </P>
<P>/* open a file for writing */ <BR>fp =3D fopen("DUMMY.FIL", =
"w"); </P>
<P>/* force an error condition by attempting to read */ <BR>ch =
=3D=20
fgetc(fp); <BR>printf("%c\n",ch); </P>
<P>if (ferror(fp)) <BR>{ <BR>/* display an error message */=20
<BR>printf("Error reading from DUMMY.FIL\n"); </P>
<P>/* reset the error and EOF indicators */ <BR>clearerr(fp); =
<BR>} </P>
<P>fclose(fp); <BR>return 0; <BR>} <BR><BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: clearviewport <BR>=B9=A6 =C4=DC: =
=C7=E5=B3=FD=CD=BC=D0=CE=CA=D3=C7=F8 <BR>=D3=C3 =B7=A8: void far=20
clearviewport(void); <BR>=B3=CC=D0=F2=C0=FD: </P>
<P>#include <BR>#include <BR>#include <BR>#include </P>
<P>#define CLIP_ON 1 /* activates clipping in viewport */ </P>
<P>int main(void) <BR>{ <BR>/* request auto detection */ <BR>int =
gdriver=20
=3D DETECT, gmode, errorcode; <BR>int ht; </P>
<P>/* initialize graphics and local variables */=20
<BR>initgraph(&gdriver, &gmode, ""); </P>
<P>/* read result of initialization */ <BR>errorcode =3D =
graphresult();=20
<BR>if (errorcode !=3D grOk) /* an error occurred */ <BR>{=20
<BR>printf("Graphics error: %s\n", grapherrormsg(errorcode));=20
<BR>printf("Press any key to halt:"); <BR>getch(); <BR>exit(1); =
/*=20
terminate with an error code */ <BR>} </P>
<P>setcolor(getmaxcolor()); <BR>ht =3D textheight("W"); </P>
<P>/* message in default full-screen viewport */ =
<BR>outtextxy(0, 0, "*=20
<-- (0, 0) in default viewport"); </P>
<P>/* create a smaller viewport */ <BR>setviewport(50, 50, =
getmaxx()-50,=20
getmaxy()-50, CLIP_ON); </P>
<P>/* display some messages */ <BR>outtextxy(0, 0, "* <-- (0, =
0) in=20
smaller viewport"); <BR>outtextxy(0, 2*ht, "Press any key to =
clear=20
viewport:"); </P>
<P>/* wait for a key */ <BR>getch(); </P>
<P>/* clear the viewport */ <BR>clearviewport(); </P>
<P>/* output another message */ <BR>outtextxy(0, 0, "Press any =
key to=20
quit:"); </P>
<P>/* clean up */ <BR>getch(); <BR>closegraph(); <BR>return 0; =
<BR>}=20
<BR><BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: _close, close <BR>=B9=A6 =C4=DC: =
=B9=D8=B1=D5=CE=C4=BC=FE=BE=E4=B1=FA <BR>=D3=C3 =B7=A8: int close(int =
handle);=20
<BR>=B3=CC=D0=F2=C0=FD: </P>
<P>#include <BR>#include <BR>#include <BR>#include </P>
<P>main() <BR>{ <BR>int handle; <BR>char buf[11] =3D =
"0123456789"; </P>
<P>/* create a file containing 10 bytes */ <BR>handle =3D =
open("NEW.FIL",=20
O_CREAT); <BR>if (handle > -1) <BR>{ <BR>write(handle, buf,=20
strlen(buf)); </P>
<P>/* close the file */ <BR>close(handle); <BR>} <BR>else <BR>{=20
<BR>printf("Error opening file\n"); <BR>} <BR>return 0; <BR>}=20
<BR><BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: clock <BR>=B9=A6 =C4=DC: =
=C8=B7=B6=A8=B4=A6=C0=ED=C6=F7=CA=B1=BC=E4 <BR>=D3=C3 =B7=A8: clock_t =
clock(void); <BR>=B3=CC=D0=F2=C0=FD:=20
</P>
<P>#include <BR>#include <BR>#include </P>
<P>int main(void) <BR>{ <BR>clock_t start, end; <BR>start =3D =
clock();=20
</P>
<P>delay(2000); </P>
<P>end =3D clock(); <BR>printf("The time was: %f\n", (end - =
start) /=20
CLK_TCK); </P>
<P>return 0; <BR>} <BR><BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: closegraph <BR>=B9=A6 =C4=DC: =
=B9=D8=B1=D5=CD=BC=D0=CE=CF=B5=CD=B3 <BR>=D3=C3 =B7=A8: void far =
closegraph(void);=20
<BR>=B3=CC=D0=F2=C0=FD: </P>
<P>#include <BR>#include <BR>#include <BR>#include </P>
<P>int main(void) <BR>{ <BR>/* request auto detection */ <BR>int =
gdriver=20
=3D DETECT, gmode, errorcode; <BR>int x, y; </P>
<P>/* initialize graphics mode */ <BR>initgraph(&gdriver,=20
&gmode, ""); </P>
<P>/* read result of initialization */ <BR>errorcode =3D =
graphresult();=20
</P>
<P>if (errorcode !=3D grOk) /* an error <BR>occurred */ <BR>{=20
<BR>printf("Graphics error: %s\n", grapherrormsg(errorcode));=20
<BR>printf("Press any key to halt:"); <BR>getch(); <BR>exit(1); =
/*=20
terminate with an error code */ <BR>} </P>
<P>x =3D getmaxx() / 2; <BR>y =3D getmaxy() / 2; </P>
<P>/* output a message */ <BR>settextjustify(CENTER_TEXT, =
CENTER_TEXT);=20
<BR>outtextxy(x, y, "Press a key to close the graphics =
system:"); </P>
<P>/* wait for a key */ <BR>getch(); </P>
<P>/* closes down the graphics system */ <BR>closegraph(); </P>
<P>printf("We're now back in text mode.\n"); <BR>printf("Press =
any key=20
to halt:"); <BR>getch(); <BR>return 0; <BR>} <BR><BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: clreol <BR>=B9=A6 =C4=DC: =
=D4=DA=CE=C4=B1=BE=B4=B0=BF=DA=D6=D0=C7=E5=B3=FD=D7=D6=B7=FB=B5=BD=D0=D0=C4=
=A9 <BR>=D3=C3 =B7=A8: void clreol(void);=20
<BR>=B3=CC=D0=F2=C0=FD: </P>
<P>#include </P>
<P>int main(void) </P>
<P>{ <BR>clrscr(); <BR>cprintf("The function CLREOL clears all=20
characters from the\r\n"); <BR>cprintf("cursor position to the =
end of=20
the line within the\r\n"); <BR>cprintf("current text window, =
without=20
moving the cursor.\r\n"); <BR>cprintf("Press any key to continue =
. .=20
."); <BR>gotoxy(14, 4); <BR>getch(); </P>
<P>clreol(); <BR>getch(); </P>
<P>return 0; <BR>} <BR><BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: clrscr <BR>=B9=A6 =C4=DC: =
=C7=E5=B3=FD=CE=C4=B1=BE=C4=A3=CA=BD=B4=B0=BF=DA <BR>=D3=C3 =B7=A8: void =
clrscr(void); <BR>=B3=CC=D0=F2=C0=FD:=20
</P>
<P>#include </P>
<P>int main(void) <BR>{ <BR>int i; </P>
<P>clrscr(); <BR>for (i =3D 0; i < 20; i++) =
<BR>cprintf("%d\r\n", i);=20
<BR>cprintf("\r\nPress any key to clear screen"); <BR>getch(); =
</P>
<P>clrscr(); <BR>cprintf("The screen has been cleared!"); =
<BR>getch();=20
</P>
<P>return 0; <BR>} <BR><BR><BR></P>
<P>=BA=AF=CA=FD=C3=FB: coreleft <BR>=B9=A6 =C4=DC: =
=B7=B5=BB=D8=CE=B4=CA=B9=D3=C3=C4=DA=B4=E6=B5=C4=B4=F3=D0=A1 <BR>=D3=C3 =
=B7=A8: unsigned coreleft(void);=20
<BR>=B3=CC=D0=F2=C0=FD: </P>
<P>#include <BR>#include </P>
<P>int main(void) <BR>{ <BR>printf("The difference between the =
highest=20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -