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

C语言中fprintf_c语言gets函数用法c语言中fprintf函数C中的fprintf()函数(fprintf()functioninC)Prototype:原型:intfprintf(FILE*filename,constchar*string,….);Parameters:参数:FILE*filename,constchar*stringetc….

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

c语言中fprintf函数

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

Prototype:

原型:

    int fprintf(FILE *filename, const char *string, . . . .);

Parameters:

参数:

    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)

#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

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

c语言中fprintf函数

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Java-Eclipse 设置自动补全

    Java-Eclipse 设置自动补全设置自动补全

    2022年6月28日
    25
  • react对象控制台输出 null 的问题

    react对象控制台输出 null 的问题

    2021年7月2日
    86
  • java事务总述_什么是先总述后详述

    java事务总述_什么是先总述后详述java事务总述一、java事务概述1.1、java事务简述1、简介事务(TRANSACTION)是作为单个逻辑工作单元执行的一系列SQL操作,这些操作作为一个整体一起向系统提交,要么都执行、要么都不执行。如果任何一个SQL操作失败,那么整个操作就都失败,所有操作都会回滚到操作前状态,或者是上一个节点。2、java事务和数据库事务的关联实际上,一个Java应用系统,如果要操作数据库,则通过JDBC来实现的。增加、修改、删除都是通过相应方法间接来实现的,事务的控制也相应转移到Java程序代码中。因

    2022年8月31日
    4
  • Java学习之servlet篇

    Java学习之servlet篇0x00前言这里就后面正式步入到javaEE的阶段了,记录一下学习内容。0x01Java中间件在Java里面常用的几个中间件在这里列出来一下:*webSp

    2021年12月12日
    46
  • mysql如何获取当前时间_mysql怎么获取当前时间「建议收藏」

    mysql如何获取当前时间_mysql怎么获取当前时间「建议收藏」mysql获取当前时间的方法:可以通过执行【selectnow();】语句来获取当前时间。还可以通过执行【selectcurrent_timestamp,current_timestamp();】语句来获取。获得当前日期+时间(date+time)函数:now()mysql>selectnow();+———————+|now()|+——-…

    2022年10月6日
    3
  • 纯c语言写银行家算法

    纯c语言写银行家算法主要参考链接:https://blog.csdn.net/houchaoqun_xmu/article/details/55540792https://liuyanzhao.com/2932.html(这个是额外贴出可以参考的连接。本文的主要参考链接依旧是第一条)[声明]本文为转载是因为代码大多数都是网上copy的,然后自己也只是微调加实现过,个人认为不可以当原创。代码全部都贴上来了,…

    2022年5月24日
    34

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号