📄 王大刚--c语言编程宝典--f.htm
字号:
<P>函数名: findfirst, findnext <BR>功 能: 搜索磁盘目录; 取得下一个匹配的findfirst模式的文件
<BR>用 法: int findfirst(char *pathname, struct ffblk *ffblk, int
attrib); <BR> int findnext(struct ffblk *ffblk); <BR>程序例: <BR>
<P>/* findnext example */ <BR>
<P>#include <stdio.h> <BR>#include <dir.h> <BR>
<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> } <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: floodfill <BR>功 能: 填充一个有界区域 <BR>用 法: void far
floodfill(int x, int y, int border); <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>
int maxx, maxy; <BR>
<P> /* initialize graphics, local variables */
<BR> initgraph(&gdriver, &gmode, ""); <BR>
<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> } <BR>
<P> maxx = getmaxx(); <BR> maxy = getmaxy(); <BR>
<P> /* select drawing color */ <BR>
setcolor(getmaxcolor()); <BR>
<P> /* select fill color */ <BR>
setfillstyle(SOLID_FILL, getmaxcolor()); <BR>
<P> /* draw a border around the screen */ <BR>
rectangle(0, 0, maxx, maxy); <BR>
<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);
<BR>
<P> /* wait for a key */ <BR> getch(); <BR>
<P> /* fill in bounded region */ <BR> floodfill(2,
2, getmaxcolor()); <BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR> <BR>
<BR> <BR>
<P>函数名: floor <BR>功 能: 向下舍入 <BR>用 法: double floor(double x);
<BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <math.h> <BR>
<P>int main(void) <BR>{ <BR> double number = 123.54;
<BR> double down, up; <BR>
<P> down = floor(number); <BR> up = ceil(number);
<BR>
<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); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: flushall <BR>功 能: 清除所有缓冲区 <BR>用 法: int flushall(void);
<BR>程序例: <BR>
<P>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> FILE *stream; <BR>
<P> /* create a file */ <BR> stream =
fopen("DUMMY.FIL", "w"); <BR>
<P> /* flush all open streams */ <BR> printf("%d
streams were flushed.\n", <BR> flushall()); <BR>
<P> /* close the file */ <BR> fclose(stream);
<BR> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: fmod <BR>功 能: 计算x对y的模, 即x/y的余数 <BR>用 法: double
fmod(double x, double y); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <math.h> <BR>
<P>int main(void) <BR>{ <BR> double x = 5.0, y = 2.0;
<BR> double result; <BR>
<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>
<BR>
<P>函数名: fnmerge <BR>功 能: 建立新文件名 <BR>用 法: void fnerge(char
*path, char *drive, char *dir); <BR>程序例: <BR>
<P>#include <string.h> <BR>#include <stdio.h> <BR>#include
<dir.h> <BR> <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]; <BR>
<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 string to separate elems */
<BR> strcpy(file,"DATA"); <BR>
strcpy(ext,".TXT"); <BR>
fnmerge(s,drive,dir,file,ext); /* merge everything into one
string */ <BR>
puts(s);
/* display resulting string */ <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<BR>
<P>函数名: fopen <BR>功 能: 打开一个流 <BR>用 法: FILE *fopen(char
*filename, char *type); <BR>程序例: <BR>
<P>#include <stdlib.h> <BR>#include <stdio.h> <BR>#include
<dir.h> <BR>
<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;
<BR>
<P> s=getenv("COMSPEC"); /* get the comspec environment
parameter */ <BR> flags=fnsplit(s,drive,dir,file,ext);
<BR>
<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);
<BR>
<P> return 0; <BR>} <BR> <BR>
<P>函数名: fprintf <BR>功 能: 传送格式化输出到一个流中 <BR>用 法: int
fprintf(FILE *stream, char *format[, argument,...]); <BR>程序例: <BR>
<P>/* Program to create backup of the <BR> AUTOEXEC.BAT file
*/ <BR>
<P>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> FILE *in, *out; <BR>
<P> if ((in = fopen("\\AUTOEXEC.BAT", "rt"))
<BR> == NULL) <BR> {
<BR> fprintf(stderr, "Cannot open input \
<BR> file.\n");
<BR> return 1; <BR> } <BR>
<P> if ((out = fopen("\\AUTOEXEC.BAK", "wt"))
<BR> == NULL) <BR> {
<BR> fprintf(stderr, "Cannot open output \
<BR> file.\n");
<BR> return 1; <BR> } <BR>
<P> while (!feof(in)) <BR>
fputc(fgetc(in), out); <BR>
<P> fclose(in); <BR> fclose(out); <BR>
return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: FP_OFF <BR>功 能: 获取远地址偏移量 <BR>用 法: unsigned FP_OFF(void
far *farptr); <BR>程序例: <BR>
<P>/* FP_OFF */ <BR>
<P>#include <dos.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> char *str = "fpoff.c"; <BR>
<P> printf("The offset of this file in memory\
<BR> is: %Fp\n",
FP_OFF(str)); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: FP_SEG <BR>功 能: 获取远地址段值 <BR>用 法: unsigned FP_SEG(void
far *farptr); <BR>程序例: <BR>
<P>/* FP_SEG */ <BR>
<P>#include <dos.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> char *filename = "fpseg.c"; <BR>
<P> printf("The offset of this file in memory\
<BR> is: %Fp\n", FP_SEG(filename)); <BR>
<P> return(0); <BR>} <BR> <BR> <BR> <BR>
<P>函数名: fputc <BR>功 能: 送一个字符到一个流中 <BR>用 法: int fputc(int ch,
FILE *stream); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> char msg[] = "Hello world";
<BR> int i = 0; <BR>
<P> while (msg[i]) <BR> {
<BR> fputc(msg[i], stdout);
<BR> i++; <BR> }
<BR> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: fputchar <BR>功 能: 送一个字符到标准输出流(stdout)中 <BR>用 法: int
fputchar(char ch); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> char msg[] = "This is a test";
<BR> int i = 0; <BR>
<P> while (msg[i]) <BR> {
<BR> fputchar(msg[i]);
<BR> i++; <BR> }
<BR> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: fputs <BR>功 能: 送一个字符到一个流中 <BR>用 法: int fputs(char
*string, FILE *stream); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> /* write a string to standard
output */ <BR> fputs("Hello world\n", stdout); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: fread <BR>功 能: 从一个流中读数据 <BR>用 法: int fread(void *ptr,
int size, int nitems, FILE *stream); <BR>程序例: <BR>
<P>#include <string.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> FILE *stream; <BR>
char msg[] = "this is a test"; <BR> char buf[20]; <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -