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