📄 ff.htm
字号:
<p>函数名: fcvt <br>
功 能: 把一个浮点数转换为字符串 <br>
用 法: char *fcvt(double value, int ndigit, int *decpt, int *sign);
<br>
程序例:
<p>#include <stdlib.h> <br>
#include <stdio.h> <br>
#include <conio.h>
<p>int main(void) <br>
{ <br>
char *string; <br>
double value; <br>
int dec, sign; <br>
int ndig = 10;
<p> clrscr(); <br>
value = 9.876; <br>
string = ecvt(value, ndig, &dec, &sign); <br>
printf("string = %s dec = %d
\ <br>
sign = %d\n", string,
dec, sign);
<p> value = -123.45; <br>
ndig= 15; <br>
string = ecvt(value,ndig,&dec,&sign); <br>
printf("string = %s dec = %d sign = %d\n", <br>
string, dec, sign);
<br>
<p> value = 0.6789e5; /* scientific <br>
notation */ <br>
ndig = 5; <br>
string = ecvt(value,ndig,&dec,&sign); <br>
printf("string = %s
dec = %d\ <br>
sign = %d\n", string,
dec, sign);
<p> return 0; <br>
} <br>
<br>
<br>
<p>函数名: fdopen <br>
功 能: 把流与一个文件句柄相接 <br>
用 法: FILE *fdopen(int handle, char *type); <br>
程序例:
<p>#include <sys\stat.h> <br>
#include <stdio.h> <br>
#include <fcntl.h> <br>
#include <io.h>
<p>int main(void) <br>
{ <br>
int handle; <br>
FILE *stream;
<p> /* open a file */ <br>
handle = open("DUMMY.FIL", O_CREAT, <br>
S_IREAD | S_IWRITE);
<p> /* now turn the handle into a stream */ <br>
stream = fdopen(handle, "w");
<p> if (stream == NULL) <br>
printf("fdopen failed\n"); <br>
else <br>
{ <br>
fprintf(stream, "Hello world\n"); <br>
fclose(stream); <br>
} <br>
return 0; <br>
} <br>
<br>
<p>函数名: feof <br>
功 能: 检测流上的文件结束符 <br>
用 法: int feof(FILE *stream); <br>
程序例:
<p>#include <stdio.h>
<p>int main(void) <br>
{ <br>
FILE *stream;
<p> /* open a file for reading */ <br>
stream = fopen("DUMMY.FIL", "r");
<p> /* read a character from the file */ <br>
fgetc(stream);
<p> /* check for EOF */ <br>
if (feof(stream)) <br>
printf("We have reached end-of-file\n");
<p> /* close the file */ <br>
fclose(stream); <br>
return 0; <br>
} <br>
<br>
<p>函数名: ferror <br>
功 能: 检测流上的错误 <br>
用 法: int ferror(FILE *stream); <br>
程序例:
<p>#include <stdio.h>
<p>int main(void) <br>
{ <br>
FILE *stream;
<p> /* open a file for writing */ <br>
stream = fopen("DUMMY.FIL", "w");
<p> /* force an error condition by attempting to read */ <br>
(void) getc(stream);
<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> /* reset the error and EOF indicators
*/ <br>
clearerr(stream); <br>
}
<p> fclose(stream); <br>
return 0; <br>
} <br>
<br>
<br>
<p>函数名: fflush <br>
功 能: 清除一个流 <br>
用 法: int fflush(FILE *stream); <br>
程序例:
<p>#include <string.h> <br>
#include <stdio.h> <br>
#include <conio.h> <br>
#include <io.h>
<p>void flush(FILE *stream);
<p>int main(void) <br>
{ <br>
FILE *stream; <br>
char msg[] = "This is a test";
<p> /* create a file */ <br>
stream = fopen("DUMMY.FIL", "w");
<p> /* write some data to the file */ <br>
fwrite(msg, strlen(msg), 1, stream);
<p> clrscr(); <br>
printf("Press any key to flush\ <br>
DUMMY.FIL:"); <br>
getch();
<p> /* flush the data to DUMMY.FIL without\ <br>
closing it */ <br>
flush(stream);
<p> printf("\nFile was flushed, Press any key\ <br>
to quit:"); <br>
getch(); <br>
return 0; <br>
}
<p>void flush(FILE *stream) <br>
{ <br>
int duphandle;
<p> /* flush the stream's internal buffer */ <br>
fflush(stream);
<p> /* make a duplicate file handle */ <br>
duphandle = dup(fileno(stream));
<p> /* close the duplicate handle to flush\ <br>
the DOS buffer */ <br>
close(duphandle); <br>
} <br>
<br>
<br>
<p>函数名: fgetc <br>
功 能: 从流中读取字符 <br>
用 法: int fgetc(FILE *stream); <br>
程序例:
<p>#include <string.h> <br>
#include <stdio.h> <br>
#include <conio.h>
<p>int main(void) <br>
{ <br>
FILE *stream; <br>
char string[] = "This is a test"; <br>
char ch;
<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 beginning of the file */ <br>
fseek(stream, 0, SEEK_SET);
<p> do <br>
{ <br>
/* read a char from the file */ <br>
ch = fgetc(stream);
<p> /* display the character */ <br>
putch(ch); <br>
} while (ch != EOF);
<p> fclose(stream); <br>
return 0; <br>
} <br>
<br>
<br>
<p>函数名: fgetchar <br>
功 能: 从流中读取字符 <br>
用 法: int fgetchar(void); <br>
程序例:
<p>#include <stdio.h>
<p>int main(void) <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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -