C语言fread函数_C语言fread

C语言fread函数_C语言freadc语言中fread函数C语言中的fread()函数(fread()functioninC)Prototype:原型:size_tfread(void*buffer,size_tlength,size_tcount,FILE*filename);Parameters:参数:void*buffer,size_tlength,si…

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

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

c语言中fread函数

C语言中的fread()函数 (fread() function in C)

Prototype:

原型:

    size_t fread(void *buffer, size_t length, size_t count, FILE *filename);

Parameters:

参数:

    void *buffer, size_t length, size_t count, FILE *filename

Return type: size_t

返回类型: size_t

Use of function:

使用功能:

The prototype of the function fread() is:

函数fread()的原型为:

    size_t fread(void *buffer, size_t length, size_t count, FILE *filename);

In the file handling, through the fread() function, we read the count number of objects of size length from the input stream filename to the array named buffer. Its returns the number of objects being read from the file. If lesser no of objects are read or EOF is encountered before then it will give an error.

在文件处理中,通过fread()函数 ,我们从输入流文件名到名为buffer的数组读取大小为长度的对象的计数 。 它返回从文件中读取的对象数。 如果较少的对象没有被读取或在此之前遇到EOF ,则它将给出错误。

C语言中的fread()示例 (fread() example in C)

#include <stdio.h>
#include <stdlib.h>

int main(){
   
   
	FILE *f;
	//initialize the arr1 with values
	int arr1[5]={
   
   1,2,3,4,5};
	int arr2[5];
	int i=0;

	//open the file for write operation
	if((f=fopen("includehelp.txt","w"))==NULL){
   
   
		//if the file does not exist print the string
		printf("Cannot open the file...");
		exit(1);
	}
	//write the values on the file
	if((fwrite(arr1,sizeof(int),5,f))!=5){
   
   
		printf("File write error....\n");
	}
	//close the file
	fclose(f);
	
	//open the file for read operation
	if((f=fopen("includehelp.txt","r"))==NULL){
   
   
		//if the file does not exist print the string
		printf("Cannot open the file...");
		exit(1);
	}
	//read the values from the file and store it into the array
	if((fread(arr2,sizeof(int),5,f))!=5){
   
   
		printf("File write error....\n");
	}
	fclose(f);
	
	printf("The array content is-\n");
	for(i=0;i<5;i++){
   
   
		printf("%d\n",arr2[i]);
	}
	
	return 0;
}

Output

输出量

fread example in c

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

c语言中fread函数

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

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

(0)
上一篇 2025年11月4日 下午3:22
下一篇 2025年11月4日 下午4:01


相关推荐

  • hmac 签名_em球衣签名

    hmac 签名_em球衣签名在提供第三方接口的时候,我们需要确认:1.消息未被其他人篡改(签名和验证签名)2.从消息中确认第三方的身份(appid)因为hash是不可逆的,所以签名的过程是不可逆的;HMACSHA1是从SHA1哈希函数构造的一种键控哈希算法,被用作HMAC(基于哈希的消息验证代码)。此HMAC进程将密钥与消息数据混合,使用哈希函数对混合结果进行哈希计算,将所得哈希值与该密钥混…

    2025年7月31日
    7
  • Arduino连接LCD1602显示屏

    Arduino连接LCD1602显示屏LCD1602液晶屏带I2C接口使用I2C接口,省IO口,只需要4条线即可。通过背光灯,和可调节对比度(就是背面蓝色那块可以旋转的调)自从1.6.6版本的IDE出来后,不断有反应LCD1602IIC液晶显示不正常,打印一字符串,却只显示第一个字符!最初解决办法换低版本IDE,就可以解决该问题!现在问题找出来了,只需要更改LiquidCrystal_I2C.cpp文件中的一个语…

    2022年7月16日
    25
  • Python函数setdefault()

    Python函数setdefault()描述 Python 字典 setdefault 函数和 get 方法类似 如果键不存在于字典中 将会添加键并将值设为默认值 注意 setdefault 返回的键如果不在字典中 会添加键 更新字典 语法 dict setdefault key default None 参数 key 这是要搜索的键 default 这是在没有找到键的情况下则返回此值 返回值此方法返回字典中可用的

    2026年3月18日
    2
  • js实现input的赋值

    js实现input的赋值

    2021年11月8日
    39
  • Gson读取文件「建议收藏」

    Gson读取文件「建议收藏」读取文件

    2022年5月15日
    50
  • ubuntu下nvm,node以及npm的安装与使用

    ubuntu下nvm,node以及npm的安装与使用

    2022年3月3日
    75

发表回复

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

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