函数名: fopen 功 能: 打开一个流 用 法: FILE *fopen(char *filename, char *type); 程序例:
#include <stdlib.h> #include <stdio.h> #include <dir.h>
int main(void) { char *s; char drive[MAXDRIVE]; char dir[MAXDIR]; char file[MAXFILE]; char ext[MAXEXT]; int flags;
s=getenv("COMSPEC"); /* get the comspec environment parameter */ flags=fnsplit(s,drive,dir,file,ext);
printf("Command processor inf\n"); if(flags & DRIVE) printf("\tdrive: %s\n",drive); if(flags & DIRECTORY) printf("\tdirectory: %s\n",dir); if(flags & FILENAME) printf("\tfile: %s\n",file); if(flags & EXTENSION) printf("\textension: %s\n",ext);
return 0; } 函数名: fclose 功 能: 关闭一个流 用 法: int fclose(FILE *stream); 程序例:
#include <string.h> #include <stdio.h>
int main(void) { FILE *fp; char buf[11] = "0123456789";
/* create a file containing 10 bytes */ fp = fopen("DUMMY.FIL", "w"); fwrite(&buf, strlen(buf), 1, fp);
/* close the file */ fclose(fp); return 0; }