📄 ff.htm
字号:
<p> /* close the file */ <br>
fclose(stream); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: ferror <br>
功 能: 检测流上的错误 <br>
用 法: int ferror(FILE *stream); <br>
程序例: </p>
<p>#include <stdio.h> </p>
<p>int main(void) <br>
{ <br>
FILE *stream; </p>
<p> /* open a file for writing */ <br>
stream = fopen("DUMMY.FIL",
"w"); </p>
<p> /* force an error condition by attempting
to read */ <br>
(void) getc(stream); </p>
<p> if (ferror(stream)) /* test for an
error on the stream */ <br>
{ <br>
/* display an error
message */ <br>
printf("Error reading
from DUMMY.FIL\n"); </p>
<p> /* reset the error and
EOF indicators */ <br>
clearerr(stream); <br>
} </p>
<p> fclose(stream); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: fflush <br>
功 能: 清除一个流 <br>
用 法: int fflush(FILE *stream); <br>
程序例: </p>
<p>#include <string.h> <br>
#include <stdio.h> <br>
#include <conio.h> <br>
#include <io.h> </p>
<p>void flush(FILE *stream); </p>
<p>int main(void) <br>
{ <br>
FILE *stream; <br>
char msg[] = "This is a test"; </p>
<p> /* create a file */ <br>
stream = fopen("DUMMY.FIL",
"w"); </p>
<p> /* write some data to the file */ <br>
fwrite(msg, strlen(msg), 1, stream); </p>
<p> clrscr(); <br>
printf("Press any key to flush\ <br>
DUMMY.FIL:"); <br>
getch(); </p>
<p> /* flush the data to DUMMY.FIL without\ <br>
closing it */ <br>
flush(stream); </p>
<p> printf("\nFile was flushed, Press
any key\ <br>
to quit:"); <br>
getch(); <br>
return 0; <br>
} </p>
<p>void flush(FILE *stream) <br>
{ <br>
int duphandle; </p>
<p> /* flush the stream's
internal buffer */ <br>
fflush(stream); </p>
<p> /* make a duplicate file
handle */ <br>
duphandle = dup(fileno(stream));
</p>
<p> /* close the duplicate handle
to flush\ <br>
the DOS buffer
*/ <br>
close(duphandle); <br>
} <br>
<br>
<br>
</p>
<p>函数名: fgetc <br>
功 能: 从流中读取字符 <br>
用 法: int fgetc(FILE *stream); <br>
程序例: </p>
<p>#include <string.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<p>int main(void) <br>
{ <br>
FILE *stream; <br>
char string[] = "This is a test"; <br>
char ch; </p>
<p> /* open a file for update */ <br>
stream = fopen("DUMMY.FIL",
"w+"); </p>
<p> /* write a string into the file */ <br>
fwrite(string, strlen(string), 1, stream); </p>
<p> /* seek to the beginning of the file */ <br>
fseek(stream, 0, SEEK_SET); </p>
<p> do <br>
{ <br>
/* read a char from the
file */ <br>
ch = fgetc(stream); </p>
<p> /* display the
character */ <br>
putch(ch); <br>
} while (ch != EOF); </p>
<p> fclose(stream); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: fgetchar <br>
功 能: 从流中读取字符 <br>
用 法: int fgetchar(void); <br>
程序例: </p>
<p>#include <stdio.h> </p>
<p>int main(void) <br>
{ <br>
char ch; </p>
<p> /* prompt the user for input */ <br>
printf("Enter a character followed by \
<br>
<Enter>: "); </p>
<p> /* read the character from stdin */ <br>
ch = fgetchar(); </p>
<p> /* display what was read */ <br>
printf("The character read is:
'%c'\n", <br>
ch); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: fgetpos <br>
功 能: 取得当前文件的句柄 <br>
用 法: int fgetpos(FILE *stream); <br>
程序例: </p>
<p>#include <string.h> <br>
#include <stdio.h> </p>
<p>int main(void) <br>
{ <br>
FILE *stream; <br>
char string[] = "This is a test"; <br>
fpos_t filepos; </p>
<p> /* open a file for update */ <br>
stream = fopen("DUMMY.FIL",
"w+"); </p>
<p> /* write a string into the file */ <br>
fwrite(string, strlen(string), 1, stream); </p>
<p> /* report the file pointer position */ <br>
fgetpos(stream, &filepos); <br>
printf("The file pointer is at byte\ <br>
%ld\n", filepos); </p>
<p> fclose(stream); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: fgets <br>
功 能: 从流中读取一字符串 <br>
用 法: char *fgets(char *string, int n, FILE
*stream); <br>
程序例: </p>
<p>#include <string.h> <br>
#include <stdio.h> </p>
<p>int main(void) <br>
{ <br>
FILE *stream; <br>
char string[] = "This is a test"; <br>
char msg[20]; </p>
<p> /* open a file for update */ <br>
stream = fopen("DUMMY.FIL",
"w+"); </p>
<p> /* write a string into the file */ <br>
fwrite(string, strlen(string), 1, stream); </p>
<p> /* seek to the start of the file */ <br>
fseek(stream, 0, SEEK_SET); </p>
<p> /* read a string from the file */ <br>
fgets(msg, strlen(string)+1, stream); </p>
<p> /* display the string */ <br>
printf("%s", msg); </p>
<p> fclose(stream); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: filelength <br>
功 能: 取文件长度字节数 <br>
用 法: long filelength(int handle); <br>
程序例: </p>
<p>#include <string.h> <br>
#include <stdio.h> <br>
#include <fcntl.h> <br>
#include <io.h> </p>
<p>int main(void) <br>
{ <br>
int handle; <br>
char buf[11] = "0123456789"; </p>
<p> /* create a file containing 10 bytes */ <br>
handle = open("DUMMY.FIL",
O_CREAT); <br>
write(handle, buf, strlen(buf)); </p>
<p> /* display the size of the file */ <br>
printf("file length in bytes:
%ld\n", <br>
filelength(handle)); </p>
<p> /* close the file */ <br>
close(handle); <br>
return 0; <br>
} <br>
<br>
</p>
<p>函数名: fillellipse <br>
功 能: 画出并填充一椭圆 <br>
用 法: void far fillellipse(int x, int y, int
xradius, int yradius); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <conio.h> </p>
<p>int main(void) <br>
{ <br>
int gdriver = DETECT, gmode; <br>
int xcenter, ycenter, i; </p>
<p>
initgraph(&gdriver,&gmode,""); <br>
xcenter = getmaxx() / 2; <br>
ycenter = getmaxy() / 2; </p>
<p> for (i=0; i<13; i++) <br>
{ <br>
setfillstyle(i,WHITE); <br>
fillellipse(xcenter,ycenter,100,50); <br>
getch(); <br>
} </p>
<p> closegraph(); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: fillpoly <br>
功 能: 画并填充一个多边形 <br>
用 法: void far fillpoly(int numpoints, int far
*polypoints); <br>
程序例: </p>
<p>#include <graphics.h> <br>
#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h> </p>
<p>int main(void) <br>
{ <br>
/* request auto detection */ <br>
int gdriver = DETECT, gmode, errorcode; <br>
int i, maxx, maxy; </p>
<p> /* our polygon array */ <br>
int poly[8]; </p>
<p> /* initialize graphics, local variables
*/ <br>
initgraph(&gdriver, &gmode,
""); </p>
<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>
<p> maxx = getmaxx(); <br>
maxy = getmaxy(); </p>
<p> poly[0] = 20;
/* 1st vertext */ <br>
poly[1] = maxy / 2; </p>
<p> poly[2] = maxx - 20; /* 2nd */ <br>
poly[3] = 20; </p>
<p> poly[4] = maxx - 50; /* 3rd */ <br>
poly[5] = maxy - 20; </p>
<p> /* <br>
4th vertex. fillpoly
automatically <br>
closes the polygon. <br>
*/ <br>
poly[6] = maxx / 2; <br>
poly[7] = maxy / 2; </p>
<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>
<p> /* draw a filled
polygon */ <br>
fillpoly(4, poly); </p>
<p> getch(); <br>
} </p>
<p> /* clean up */ <br>
closegraph(); <br>
return 0; <br>
} <br>
<br>
<br>
</p>
<p>函数名: findfirst, findnext <br>
功 能: 搜索磁盘目录;
取得下一个匹配的findfirst模式的文件 <br>
用 法: int findfirst(char *pathname, struct ffblk
*ffblk, int attrib); <br>
int findnext(struct ffblk *ffblk); <br>
程序例: </p>
<p>/* findnext example */ </p>
<p>#include <stdio.h> <br>
#include <dir.h> </p>
<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>
<p> return 0; <br>
} <br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -