📄 ff.htm
字号:
<P>函数名: FP_OFF<BR>功 能: 获取远地址偏移量<BR>用 法: unsigned FP_OFF(void far *farptr);<BR>程序例:<P>/* FP_OFF */<P>#include <dos.h><BR>#include <stdio.h><P>int main(void)<BR>{<BR> char *str = "fpoff.c";<P> printf("The offset of this file in memory\<BR> is: %Fp\n",FP_OFF(str));<P> return 0;<BR>}<BR> <BR> <P>函数名: FP_SEG<BR>功 能: 获取远地址段值<BR>用 法: unsigned FP_SEG(void far *farptr);<BR>程序例:<P>/* FP_SEG */<P>#include <dos.h><BR>#include <stdio.h><P>int main(void)<BR>{<BR> char *filename = "fpseg.c";<P> printf("The offset of this file in memory\<BR> is: %Fp\n", FP_SEG(filename));<P> return(0);<BR>}<BR> <BR> <BR> <P>函数名: fputc<BR>功 能: 送一个字符到一个流中<BR>用 法: int fputc(int ch, FILE *stream);<BR>程序例:<P>#include <stdio.h><P>int main(void)<BR>{<BR> char msg[] = "Hello world";<BR> int i = 0;<P> while (msg[i])<BR> {<BR> fputc(msg[i], stdout);<BR> i++;<BR> }<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: fputchar<BR>功 能: 送一个字符到标准输出流(stdout)中<BR>用 法: int fputchar(char ch);<BR>程序例:<P>#include <stdio.h><P>int main(void)<BR>{<BR> char msg[] = "This is a test";<BR> int i = 0;<P> while (msg[i])<BR> {<BR> fputchar(msg[i]);<BR> i++;<BR> }<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: fputs<BR>功 能: 送一个字符到一个流中<BR>用 法: int fputs(char *string, FILE *stream);<BR>程序例:<P>#include <stdio.h><P>int main(void)<BR>{<BR> /* write a string to standard output */<BR> fputs("Hello world\n", stdout);<P> return 0;<BR>}<BR> <BR> <BR> <P>函数名: fread<BR>功 能: 从一个流中读数据<BR>用 法: int fread(void *ptr, int size, int nitems, FILE *stream);<BR>程序例:<P>#include <string.h><BR>#include <stdio.h><P>int main(void)<BR>{<BR> FILE *stream;<BR> char msg[] = "this is a test";<BR> char buf[20];<P> if ((stream = fopen("DUMMY.FIL", "w+"))<BR> == NULL)<BR> {<BR> fprintf(stderr,<BR> "Cannot open output file.\n");<BR> return 1;<BR> }<P> /* write some data to the file */<BR> fwrite(msg, strlen(msg)+1, 1, stream);<P> /* seek to the beginning of the file */<BR> fseek(stream, SEEK_SET, 0);<P> /* read the data and display it */<BR> fread(buf, strlen(msg)+1, 1, stream);<BR> printf("%s\n", buf);<P> fclose(stream);<BR> return 0;<BR>}<BR> <BR> <P>函数名: free<BR>功 能: 释放已分配的块<BR>用 法: void free(void *ptr);<BR>程序例:<P>#include <string.h><BR>#include <stdio.h><BR>#include <alloc.h><P>int main(void)<BR>{<BR> char *str;<P> /* allocate memory for string */<BR> str = malloc(10);<P> /* copy "Hello" to string */<BR> strcpy(str, "Hello");<P> /* display string */<BR> printf("String is %s\n", str);<P> /* free memory */<BR> free(str);<P> return 0;<BR>}<BR> <P>函数名: freemem<BR>功 能: 释放先前分配的DOS内存块<BR>用 法: int freemem(unsigned seg);<BR>程序例:<P>#include <dos.h><BR>#include <alloc.h><BR>#include <stdio.h><P>int main(void)<BR>{<BR> unsigned int size, segp;<BR> int stat;<P> size = 64; /* (64 x 16) = 1024 bytes */<BR> stat = allocmem(size, &segp);<BR> if (stat < 0)<BR> printf("Allocated memory at segment:\<BR> %x\n", segp);<BR> else<BR> printf("Failed: maximum number of\<BR> paragraphs available is %u\n",<BR> stat);<BR> freemem(segp);<P> return 0;<BR>}<BR> <BR> <P>函数名: freopen<BR>功 能: 替换一个流<BR>用 法: FILE *freopen(char *filename, char *type, FILE *stream);<BR>程序例:<P>#include <stdio.h><P>int main(void)<BR>{<BR> /* redirect standard output to a file */<BR> if (freopen("OUTPUT.FIL", "w", stdout)<BR> == NULL)<BR> fprintf(stderr, "error redirecting\<BR> stdout\n");<P> /* this output will go to a file */<BR> printf("This will go into a file.");<P> /* close the standard output stream */<BR> fclose(stdout);<P> return 0;<BR>}<BR> <BR> <BR> <P>函数名: frexp<BR>功 能: 把一个双精度数分解为尾数的指数<BR>用 法: double frexp(double value, int *eptr);<BR>程序例:<P>#include <math.h><BR>#include <stdio.h><P>int main(void)<BR>{<BR> double mantissa, number;<BR> int exponent;<P> number = 8.0;<BR> mantissa = frexp(number, &exponent);<P> printf("The number %lf is ", number);<BR> printf("%lf times two to the ", mantissa);<BR> printf("power of %d\n", exponent);<P> return 0;<BR>}<BR> <BR> <P>函数名: fscanf<BR>功 能: 从一个流中执行格式化输入<BR>用 法: int fscanf(FILE *stream, char *format[,argument...]);<BR>程序例:<P>#include <stdlib.h><BR>#include <stdio.h><P>int main(void)<BR>{<BR> int i;<P> printf("Input an integer: ");<P> /* read an integer from the<BR> standard input stream */<BR> if (fscanf(stdin, "%d", &i))<BR> printf("The integer read was: %i\n",<BR> i);<BR> else<BR> {<BR> fprintf(stderr, "Error reading an \<BR> integer from stdin.\n");<BR> exit(1);<BR> }<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: fseek<BR>功 能: 重定位流上的文件指针<BR>用 法: int fseek(FILE *stream, long offset, int fromwhere);<BR>程序例:<P>#include <stdio.h><P>long filesize(FILE *stream);<P>int main(void)<BR>{<BR> FILE *stream;<P> stream = fopen("MYFILE.TXT", "w+");<BR> fprintf(stream, "This is a test");<BR> printf("Filesize of MYFILE.TXT is %ld bytes\n", filesize(stream));<BR> fclose(stream);<BR> return 0;<BR>}<P>long filesize(FILE *stream)<BR>{<BR> long curpos, length;<P> curpos = ftell(stream);<BR> fseek(stream, 0L, SEEK_END);<BR> length = ftell(stream);<BR> fseek(stream, curpos, SEEK_SET);<BR> return length;<BR>}<BR> <BR> <BR> <BR> <BR> <P>函数名: fsetpos<BR>功 能: 定位流上的文件指针<BR>用 法: int fsetpos(FILE *stream, const fpos_t *pos);<BR>程序例:<P>#include <stdlib.h><BR>#include <stdio.h><P>void showpos(FILE *stream);<P>int main(void)<BR>{<BR> FILE *stream;<BR> fpos_t filepos;<P> /* open a file for update */<BR> stream = fopen("DUMMY.FIL", "w+");<P> /* save the file pointer position */<BR> fgetpos(stream, &filepos);<P> /* write some data to the file */<BR> fprintf(stream, "This is a test");<P> /* show the current file position */<BR> showpos(stream);<P> /* set a new file position, display it */<BR> if (fsetpos(stream, &filepos) == 0)<BR> showpos(stream);<BR> else<BR> {<BR> fprintf(stderr, "Error setting file\<BR> pointer.\n");<BR> exit(1);<BR> }<P> /* close the file */<BR> fclose(stream);<BR> return 0;<BR>}<P>void showpos(FILE *stream)<BR>{<BR> fpos_t pos;<P> /* display the current file pointer<BR> position of a stream */<BR> fgetpos(stream, &pos);<BR> printf("File position: %ld\n", pos);<BR>}<BR> <P>函数名: fstat<BR>功 能: 获取打开文件信息<BR>用 法: int fstat(char *handle, struct stat *buff);<BR>程序例:<P>#include <sys\stat.h><BR>#include <stdio.h><BR>#include <time.h><P>int main(void)<BR>{<BR> struct stat statbuf;<BR> FILE *stream;<P> /* open a file for update */<BR> if ((stream = fopen("DUMMY.FIL", "w+"))<BR> == NULL)<BR> {<BR> fprintf(stderr, "Cannot open output\<BR> file.\n");<BR> return(1);<BR> }<BR> fprintf(stream, "This is a test");<BR> fflush(stream);<P> /* get information about the file */<BR> fstat(fileno(stream), &statbuf);<BR> fclose(stream);<P> /* display the information returned */<BR> if (statbuf.st_mode & S_IFCHR)<BR> printf("Handle refers to a device.\n");<BR> if (statbuf.st_mode & S_IFREG)<BR> printf("Handle refers to an ordinary\<BR> file.\n");<BR> if (statbuf.st_mode & S_IREAD)<BR> printf("User has read permission on\<BR> file.\n");<BR> if (statbuf.st_mode & S_IWRITE)<BR> printf("User has write permission on\<BR> file.\n");<P> printf("Drive letter of file: %c\n",<BR> 'A'+statbuf.st_dev);<BR> printf("Size of file in bytes: %ld\n",<BR> statbuf.st_size);<BR> printf("Time file last opened: %s\n",<BR> ctime(&statbuf.st_ctime));<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: ftell<BR>功 能: 返回当前文件指针<BR>用 法: long ftell(FILE *stream);<BR>程序例:<P>#include <stdio.h><P>int main(void)<BR>{<BR> FILE *stream;<P> stream = fopen("MYFILE.TXT", "w+");<BR> fprintf(stream, "This is a test");<BR> printf("The file pointer is at byte \<BR> %ld\n", ftell(stream));<BR> fclose(stream);<BR> return 0;<BR>}<BR> <BR> <BR> <P>函数名: fwrite<BR>功 能: 写内容到流中<BR>用 法: int fwrite(void *ptr, int size, int nitems, FILE *stream);<BR>程序例:<P>#include <stdio.h><P>struct mystruct<BR>{<BR> int i;<BR> char ch;<BR>};<P>int main(void)<BR>{<BR> FILE *stream;<BR> struct mystruct s;<P> if ((stream = fopen("TEST.$$$", "wb")) == NULL) /* openfile TEST.$$$ */<BR> {<BR> fprintf(stderr, "Cannot open outputfile.\n");<BR> return 1;<BR> }<BR> s.i = 0;<BR> s.ch = 'A';<BR> fwrite(&s, sizeof(s), 1, stream); /* write structs to file */<BR> fclose(stream); /* close file */<BR> return 0;<BR>}<BR> <P> <A HREF="index.html">返回目录</A><BR> <P></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -