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

📄 ff.htm

📁 turbo c
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<BR>{<BR>&nbsp;&nbsp; char ch;<P>&nbsp;&nbsp; /* prompt the user for input */<BR>&nbsp;&nbsp; printf("Enter a character followed by \<BR>&nbsp;&nbsp; &lt;Enter>: ");<P>&nbsp;&nbsp; /* read the character from stdin */<BR>&nbsp;&nbsp; ch = fgetchar();<P>&nbsp;&nbsp; /* display what was read */<BR>&nbsp;&nbsp; printf("The character read is: '%c'\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ch);<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<P>函数名: fgetpos<BR>功&nbsp; 能: 取得当前文件的句柄<BR>用&nbsp; 法: int fgetpos(FILE *stream);<BR>程序例:<P>#include &lt;string.h><BR>#include &lt;stdio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; FILE *stream;<BR>&nbsp;&nbsp; char string[] = "This is a test";<BR>&nbsp;&nbsp; fpos_t filepos;<P>&nbsp;&nbsp; /* open a file for update */<BR>&nbsp;&nbsp; stream = fopen("DUMMY.FIL", "w+");<P>&nbsp;&nbsp; /* write a string into the file */<BR>&nbsp;&nbsp; fwrite(string, strlen(string), 1, stream);<P>&nbsp;&nbsp; /* report the file pointer position */<BR>&nbsp;&nbsp; fgetpos(stream, &amp;filepos);<BR>&nbsp;&nbsp; printf("The file pointer is at byte\<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %ld\n", filepos);<P>&nbsp;&nbsp; fclose(stream);<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<P>函数名: fgets<BR>功&nbsp; 能: 从流中读取一字符串<BR>用&nbsp; 法: char *fgets(char *string, int n, FILE *stream);<BR>程序例:<P>#include &lt;string.h><BR>#include &lt;stdio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; FILE *stream;<BR>&nbsp;&nbsp; char string[] = "This is a test";<BR>&nbsp;&nbsp; char msg[20];<P>&nbsp;&nbsp; /* open a file for update */<BR>&nbsp;&nbsp; stream = fopen("DUMMY.FIL", "w+");<P>&nbsp;&nbsp; /* write a string into the file */<BR>&nbsp;&nbsp; fwrite(string, strlen(string), 1, stream);<P>&nbsp;&nbsp; /* seek to the start of the file */<BR>&nbsp;&nbsp; fseek(stream, 0, SEEK_SET);<P>&nbsp;&nbsp; /* read a string from the file */<BR>&nbsp;&nbsp; fgets(msg, strlen(string)+1, stream);<P>&nbsp;&nbsp; /* display the string */<BR>&nbsp;&nbsp; printf("%s", msg);<P>&nbsp;&nbsp; fclose(stream);<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<P>函数名: filelength<BR>功&nbsp; 能: 取文件长度字节数<BR>用&nbsp; 法: long filelength(int handle);<BR>程序例:<P>#include &lt;string.h><BR>#include &lt;stdio.h><BR>#include &lt;fcntl.h><BR>#include &lt;io.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; int handle;<BR>&nbsp;&nbsp; char buf[11] = "0123456789";<P>&nbsp;&nbsp; /* create a file containing 10 bytes */<BR>&nbsp;&nbsp; handle = open("DUMMY.FIL", O_CREAT);<BR>&nbsp;&nbsp; write(handle, buf, strlen(buf));<P>&nbsp;&nbsp; /* display the size of the file */<BR>&nbsp;&nbsp; printf("file length in bytes: %ld\n",<BR>&nbsp;&nbsp; filelength(handle));<P>&nbsp;&nbsp; /* close the file */<BR>&nbsp;&nbsp; close(handle);<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<P>函数名: fillellipse<BR>功&nbsp; 能: 画出并填充一椭圆<BR>用&nbsp; 法: void far fillellipse(int x, int y, int xradius, int yradius);<BR>程序例:<P>#include &lt;graphics.h><BR>#include &lt;conio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode;<BR>&nbsp;&nbsp; int xcenter, ycenter, i;<P>&nbsp;&nbsp; initgraph(&amp;gdriver,&amp;gmode,"");<BR>&nbsp;&nbsp; xcenter = getmaxx() / 2;<BR>&nbsp;&nbsp; ycenter = getmaxy() / 2;<P>&nbsp;&nbsp; for (i=0; i&lt;13; i++)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setfillstyle(i,WHITE);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fillellipse(xcenter,ycenter,100,50);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<P>函数名: fillpoly<BR>功&nbsp; 能: 画并填充一个多边形<BR>用&nbsp; 法: void far fillpoly(int numpoints, int far *polypoints);<BR>程序例:<P>#include &lt;graphics.h><BR>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;conio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; /* request auto detection */<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;<BR>&nbsp;&nbsp; int i, maxx, maxy;<P>&nbsp;&nbsp; /* our polygon array */<BR>&nbsp;&nbsp; int poly[8];<P>&nbsp;&nbsp; /* initialize graphics, local variables */<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");<P>&nbsp;&nbsp; /* read result of initialization */<BR>&nbsp;&nbsp; errorcode = graphresult();<BR>&nbsp;&nbsp; if (errorcode != grOk)<BR>&nbsp;&nbsp; /* an error occurred */<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;grapherrormsg(errorcode));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* terminate with an error code */<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; maxx = getmaxx();<BR>&nbsp;&nbsp; maxy = getmaxy();<P>&nbsp;&nbsp; poly[0] = 20;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* 1st vertext */<BR>&nbsp;&nbsp; poly[1] = maxy / 2;<P>&nbsp;&nbsp; poly[2] = maxx - 20; /* 2nd */<BR>&nbsp;&nbsp; poly[3] = 20;<P>&nbsp;&nbsp; poly[4] = maxx - 50; /* 3rd */<BR>&nbsp;&nbsp; poly[5] = maxy - 20;<P>&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4th vertex. fillpoly automatically<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; closes the polygon.<BR>&nbsp;&nbsp; */<BR>&nbsp;&nbsp; poly[6] = maxx / 2;<BR>&nbsp;&nbsp; poly[7] = maxy / 2;<P>&nbsp;&nbsp; /* loop through the fill patterns */<BR>&nbsp;&nbsp; for (i=EMPTY_FILL; i&lt;USER_FILL; i++)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* set fill pattern */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setfillstyle(i, getmaxcolor());<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* draw a filled polygon */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fillpoly(4, poly);<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; /* clean up */<BR>&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<P>函数名: findfirst, findnext<BR>功&nbsp; 能: 搜索磁盘目录; 取得下一个匹配的findfirst模式的文件<BR>用&nbsp; 法: int findfirst(char *pathname, struct ffblk *ffblk, intattrib);<BR>&nbsp;int findnext(struct ffblk *ffblk);<BR>程序例:<P>/* findnext example */<P>#include &lt;stdio.h><BR>#include &lt;dir.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; struct ffblk ffblk;<BR>&nbsp;&nbsp; int done;<BR>&nbsp;&nbsp; printf("Directory listing of *.*\n");<BR>&nbsp;&nbsp; done = findfirst("*.*",&amp;ffblk,0);<BR>&nbsp;&nbsp; while (!done)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("&nbsp; %s\n", ffblk.ff_name);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; done = findnext(&amp;ffblk);<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<P>函数名: floodfill<BR>功&nbsp; 能: 填充一个有界区域<BR>用&nbsp; 法: void far floodfill(int x, int y, int border);<BR>程序例:<P>#include &lt;graphics.h><BR>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;conio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; /* request auto detection */<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;<BR>&nbsp;&nbsp; int maxx, maxy;<P>&nbsp;&nbsp; /* initialize graphics, local variables */<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");<P>&nbsp;&nbsp; /* read result of initialization */<BR>&nbsp;&nbsp; errorcode = graphresult();<BR>&nbsp;&nbsp; if (errorcode != grOk)<BR>&nbsp;&nbsp; /* an error occurred */<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Graphics error: %s\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;grapherrormsg(errorcode));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Press any key to halt:");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* terminate with an error code */<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; maxx = getmaxx();<BR>&nbsp;&nbsp; maxy = getmaxy();<P>&nbsp;&nbsp; /* select drawing color */<BR>&nbsp;&nbsp; setcolor(getmaxcolor());<P>&nbsp;&nbsp; /* select fill color */<BR>&nbsp;&nbsp; setfillstyle(SOLID_FILL, getmaxcolor());<P>&nbsp;&nbsp; /* draw a border around the screen */<BR>&nbsp;&nbsp; rectangle(0, 0, maxx, maxy);<P>&nbsp;&nbsp; /* draw some circles */<BR>&nbsp;&nbsp; circle(maxx / 3, maxy /2, 50);<BR>&nbsp;&nbsp; circle(maxx / 2, 20, 100);<BR>&nbsp;&nbsp; circle(maxx-20, maxy-50, 75);<BR>&nbsp;&nbsp; circle(20, maxy-20, 25);<P>&nbsp;&nbsp; /* wait for a key */<BR>&nbsp;&nbsp; getch();<P>&nbsp;&nbsp; /* fill in bounded region */<BR>&nbsp;&nbsp; floodfill(2, 2, getmaxcolor());<P>&nbsp;&nbsp; /* clean up */<BR>&nbsp;&nbsp; getch();<BR>&nbsp;&nbsp; closegraph();<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<P>函数名: floor<BR>功&nbsp; 能: 向下舍入<BR>用&nbsp; 法: double floor(double x);<BR>程序例:<P>#include &lt;stdio.h><BR>#include &lt;math.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; double number = 123.54;<BR>&nbsp;&nbsp; double down, up;<P>&nbsp;&nbsp; down = floor(number);<BR>&nbsp;&nbsp; up = ceil(number);<P>&nbsp;&nbsp; printf("original number&nbsp;&nbsp;&nbsp;&nbsp; %10.2lf\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; number);<BR>&nbsp;&nbsp; printf("number rounded down %10.2lf\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; down);<BR>&nbsp;&nbsp; printf("number rounded up&nbsp;&nbsp; %10.2lf\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; up);<P>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<P>函数名: flushall<BR>功&nbsp; 能: 清除所有缓冲区<BR>用&nbsp; 法: int flushall(void);<BR>程序例:<P>#include &lt;stdio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; FILE *stream;<P>&nbsp;&nbsp; /* create a file */<BR>&nbsp;&nbsp; stream = fopen("DUMMY.FIL", "w");<P>&nbsp;&nbsp; /* flush all open streams */<BR>&nbsp;&nbsp; printf("%d streams were flushed.\n",<BR>&nbsp;&nbsp; flushall());<P>&nbsp;&nbsp; /* close the file */<BR>&nbsp;&nbsp; fclose(stream);<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<P>函数名: fmod<BR>功&nbsp; 能: 计算x对y的模, 即x/y的余数<BR>用&nbsp; 法: double fmod(double x, double y);<BR>程序例:<P>#include &lt;stdio.h><BR>#include &lt;math.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; double x = 5.0, y = 2.0;<BR>&nbsp;&nbsp; double result;<P>&nbsp;&nbsp; result = fmod(x,y);<BR>&nbsp;&nbsp; printf("The remainder of (%lf / %lf) is \<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %lf\n", x, y,result);<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<P>函数名: fnmerge<BR>功&nbsp; 能: 建立新文件名<BR>用&nbsp; 法: void fnerge(char *path, char *drive, char *dir);<BR>程序例:<P>#include &lt;string.h><BR>#include &lt;stdio.h><BR>#include &lt;dir.h><BR>&nbsp;<P>int main(void)<BR>{<BR>&nbsp;&nbsp;&nbsp; char s[MAXPATH];<BR>&nbsp;&nbsp;&nbsp; char drive[MAXDRIVE];<BR>&nbsp;&nbsp;&nbsp; char dir[MAXDIR];<BR>&nbsp;&nbsp;&nbsp; char file[MAXFILE];<BR>&nbsp;&nbsp;&nbsp; char ext[MAXEXT];<P>&nbsp;&nbsp;&nbsp; getcwd(s,MAXPATH);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* get the current working directory */<BR>&nbsp;&nbsp;&nbsp; strcat(s,"\\");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* append on a trailing \ character */<BR>&nbsp;&nbsp;&nbsp; fnsplit(s,drive,dir,file,ext); /* split the stringto separate elems */<BR>&nbsp;&nbsp;&nbsp; strcpy(file,"DATA");<BR>&nbsp;&nbsp;&nbsp; strcpy(ext,".TXT");<BR>&nbsp;&nbsp;&nbsp; fnmerge(s,drive,dir,file,ext);&nbsp;&nbsp; /* mergeeverything into one string */<BR>&nbsp;&nbsp;&nbsp; puts(s);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* display resulting string */<P>&nbsp;&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<P>函数名: fopen<BR>功&nbsp; 能: 打开一个流<BR>用&nbsp; 法: FILE *fopen(char *filename, char *type);<BR>程序例:<P>#include &lt;stdlib.h><BR>#include &lt;stdio.h><BR>#include &lt;dir.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp;&nbsp; char *s;<BR>&nbsp;&nbsp;&nbsp; char drive[MAXDRIVE];<BR>&nbsp;&nbsp;&nbsp; char dir[MAXDIR];<BR>&nbsp;&nbsp;&nbsp; char file[MAXFILE];<BR>&nbsp;&nbsp;&nbsp; char ext[MAXEXT];<BR>&nbsp;&nbsp;&nbsp; int flags;<P>&nbsp;&nbsp;&nbsp; s=getenv("COMSPEC"); /* get the comspec environmentparameter */<BR>&nbsp;&nbsp;&nbsp; flags=fnsplit(s,drive,dir,file,ext);<P>&nbsp;&nbsp;&nbsp; printf("Command processor info:\n");<BR>&nbsp;&nbsp;&nbsp; if(flags &amp; DRIVE)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("\tdrive: %s\n",drive);<BR>&nbsp;&nbsp;&nbsp; if(flags &amp; DIRECTORY)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("\tdirectory: %s\n",dir);<BR>&nbsp;&nbsp;&nbsp; if(flags &amp; FILENAME)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("\tfile: %s\n",file);<BR>&nbsp;&nbsp;&nbsp; if(flags &amp; EXTENSION)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("\textension: %s\n",ext);<P>&nbsp;&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<P>函数名: fprintf<BR>功&nbsp; 能: 传送格式化输出到一个流中<BR>用&nbsp; 法: int fprintf(FILE *stream, char *format[, argument,...]);<BR>程序例:<P>/* Program to create backup of the<BR>&nbsp;&nbsp; AUTOEXEC.BAT file */<P>#include &lt;stdio.h><P>int main(void)<BR>{<BR>&nbsp;&nbsp; FILE *in, *out;<P>&nbsp;&nbsp; if ((in = fopen("\\AUTOEXEC.BAT", "rt"))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; == NULL)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fprintf(stderr, "Cannot open input \<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file.\n");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 1;<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; if ((out = fopen("\\AUTOEXEC.BAK", "wt"))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; == NULL)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fprintf(stderr, "Cannot open output\<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file.\n");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 1;<BR>&nbsp;&nbsp; }<P>&nbsp;&nbsp; while (!feof(in))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fputc(fgetc(in), out);<P>&nbsp;&nbsp; fclose(in);<BR>&nbsp;&nbsp; fclose(out);<BR>&nbsp;&nbsp; return 0;<BR>}<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;

⌨️ 快捷键说明

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