前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C语言中fprintf_c语言gets函数用法

C语言中fprintf_c语言gets函数用法

作者头像
全栈程序员站长
发布2022-09-27 10:02:38
8650
发布2022-09-27 10:02:38
举报
文章被收录于专栏:全栈程序员必看

c语言中fprintf函数

C中的fprintf()函数 (fprintf() function in C)

Prototype:

原型:

代码语言:javascript
复制
    int fprintf(FILE *filename, const char *string, . . . .);

Parameters:

参数:

代码语言:javascript
复制
    FILE *filename, const char *string etc.

Return type: int

返回类型: int

Use of function:

使用功能:

Like printf() function, fprintf() function is used to write the argument statement string on the file stream. Through the fprintf() function we write or store the values with the string. The prototype of the function fprintf() is: int fprintf(FILE *filename, const char *string, . . . .);

与printf()函数类似, fprintf()函数用于在文件流上写入参数声明字符串。 通过fprintf()函数,我们可以将值写入或存储在字符串中。 函数fprintf()的原型是: int fprintf(FILE * filename,const char * string,。。。);

Here string is the user defined string along with the existing data types (likes int, float, char etc).

这里的string是用户定义的字符串以及现有的数据类型(例如int,float,char等)。

C中的fprintf()示例 (fprintf() example in C)

代码语言:javascript
复制
#include<stdio.h>
#include<stdlib.h>
int main()
{
   
   
	//Initialize the file pointer
	FILE *f;
	char ch[100];
	
	// open the file for read and write operation
	if((f=fopen("includehelp.txt","r+"))==NULL){
   
   
		//if the file does not exist print the string
		printf("Cannot open the file...");
		exit(1);
	}
	
	for(int i=0;i<10;i++){
   
   
		//enter the strings with values in the file
		fprintf(f,"The count number is %d\n",i+1);	
	}
	fclose(f);
	
	// open the file for read and write operation
	if((f=fopen("includehelp.txt","r+"))==NULL){
   
   
		//if the file does not exist print the string
		printf("Cannot open the file...");
		exit(1);
	}

	printf("File content is--\n");
	printf("\n...............print the strings..............\n\n");
	while(!feof(f)){
   
   
		//takes the first 100 character in the character array 
		fgets(ch,100,f);
		//and print the strings
		printf("%s",ch);
	}
	//close the file
	fclose(f);
	
	return 0;
}

Output

输出量

fprintf example in c
fprintf example in c

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

c语言中fprintf函数

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/180603.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • C中的fprintf()函数 (fprintf() function in C)
  • C中的fprintf()示例 (fprintf() example in C)
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档