fopen函数的用法示例_使用示例的C语言中的fopen()函数

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

输出量

fopen example in c

翻译自: https://www.includehelp.com/c-programs/fopen-function-in-c-language-with-example.aspx

fopen函数的用法示例

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值