?? 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) /* open
file TEST.$$$ */
<BR> {
<BR> fprintf(stderr, "Cannot open output
file.\n");
<BR> return 1;
<BR> }
<BR> s.i = 0;
<BR> s.ch = 'A';
<BR> fwrite(&s, sizeof(s), 1, stream); /* write struct
s 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 + -