fopen函数的用法示例
C语言中的fopen()函数 (fopen() function in C)
Prototype:
原型:
FILE *fopen(const char* filename, const char* mode);
Parameters:
参数:
const char* filename, const char* mode
Return type: FILE*
返回类型: FILE *
Use of function:
使用功能:
The fopen() function opens a stream which links with a file. The prototype of this function is: FILE *fopen(const char* filename, const char* mode);
fopen()函数打开一个与文件链接的流。 这个函数的原型是: FILE * fopen(const char * filename,const char * mode);
Where,
哪里,
filename: Name of the file which you want to work.
filename :要工作的文件名 。
mode: The operation modes like read, write etc.
模式 :操作模式,如读取,写入等。
C语言中的fopen()示例 (fopen() example in C)
#include <stdio.h>
#include <stdlib.h>
int main(){
//create two files pointer
FILE *f1,*f2;
char s[20];
//open file for reading
f1=fopen("includehelp.txt","w");
printf("File is created for write operation\n");
printf("Enter any string\n");
scanf("%s",&s);
//enter the string into the file
fputs(s,f1);
fclose(f1);
//append file for further operation
f2=fopen("includehelp.txt","a");
printf("File is appended\n\n");
fprintf(f2,"%s","_tutorial");
fclose(f2);
//check the file's existence
if((f2=fopen("includehelp.txt","r"))==NULL){
printf("file cannot open\n");
exit(1);
}
//read the content from the file
fscanf(f2,"%s", s);
printf("%s",s);
fclose(f2);
return 0;
}
Output
输出量
翻译自: https://www.includehelp.com/c-programs/fopen-function-in-c-language-with-example.aspx
fopen函数的用法示例