c++freopen函数_使用示例的C语言中的freopen()函数

c++freopen函数

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

Prototype:

原型:

    FILE* freopen(const char *str, const char *mode, FILE *stream);

Parameters:

参数:

    const char *str, const char *mode, FILE *stream

Return type: FILE*

返回类型: FILE *

Use of function:

使用功能:

The prototype of the function freopen() is:

函数freopen()的原型为:

    FILE* freopen(const char *str, const char *mode, FILE *stream);

The freopen() function opens the existing stream into another file. The end-of-file and error flag is cleared in this process. The file named as str with its operation mode, opens it into the file stream named as stream. The freopen() function acts similar to the fopen() function. In the following output we can see the work of the function.

freopen()函数将现有流打开到另一个文件中。 文件结束和错误标志在此过程中被清除。 以其操作模式命名为str的文件将其打开到名为stream的文件流中 。 freopen()函数的作用类似于fopen()函数。 在以下输出中,我们可以看到该函数的工作。

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

#include <stdio.h>
#include <stdlib.h>
int main(){
//Initialize the file pointer
FILE *f,*fp;
//Take a array of characters 
char ch[100];
//Create the file for write operation
f=fopen("includehelp.txt","w");
printf("Enter five strings\n");
for(int i=0;i<4;i++){
//take the strings from the users
scanf("%[^\n]",&ch);
//write back to the file
fputs(ch,f);
//every time take a new line for the new entry string 
//except for last entry.Otherwise print the last line twice
fputs("\n",f);
//clear the stdin stream buffer
//if we don't write this then after taking string 
fflush(stdin);
}
//%[^\n] is waiting for the '\n' or white space
//take the strings from the users
scanf("%[^\n]",&ch);
fputs(ch,f);
//reopen the file for read operation
fp=freopen("includehelp.txt","r",fp); 
printf("File content is--\n");
printf("\n...............print the strings..............\n\n");
while(!feof(fp)){
//takes the first 100 character in the character array 
fgets(ch,100,fp);
//and print the strings
printf("%s",ch);
}
//close the files
fclose(fp);
fclose(f);
return 0;
}

Output

输出量

freopen example in c

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

c++freopen函数

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/542087.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python—文件

1 . 文件的基本操作&#xff1a; 文件读取三部曲&#xff1a; 打开操作关闭&#xff08;如果不关闭会占用文件描述符&#xff09; 打开文件&#xff1a; f open(/tmp/passwdd,w)操作文件&#xff1a; 1 . 读操作&#xff1a; f.read()content f.read()print(content) 2 …

基本概念学习(7000)--P2P对等网络

对等网络&#xff0c;即对等计算机网络&#xff0c;是一种在对等者&#xff08;Peer&#xff09;之间分配任务和工作负载的分布式应用架构[1] &#xff0c;是对等计算模型在应用层形成的一种组网或网络形式。“Peer”在英语里有“对等者、伙伴、对端”的意义。因此&#xff0c;…

c语言for循环++_C ++程序使用循环查找数字的幂

c语言for循环Here, we are going to calculate the value of Nth power of a number without using pow function. 在这里&#xff0c;我们将不使用pow函数来计算数字的N 次幂的值 。 The idea is using loop. We will be multiplying a number (initially with value 1) by t…

厦门one_理想ONE真是“500万内最好的车”?

提起罗永浩&#xff0c;不少人还停留在“砸冰箱、造手机”等早期事件。随着网络直播的兴起&#xff0c;罗永浩转战直播带货行业&#xff0c;但老罗毕竟是老罗&#xff0c;雷人语录一点没比以前少。前一段时间&#xff0c;罗永浩在微博中称&#xff1a;“理想ONE是你能在这个价位…

Data Collection

众所周知&#xff0c;计算机领域论文是要以实验为基础的&#xff0c;而实验的原料就是数据。不管是在图像&#xff0c;文字或者语音领域&#xff0c;开源的数据都十分宝贵和重要。这里主要收集各领域的一些常用的公开数据集。 计算机视觉&#xff1a; 【ImageNet】 【Caltech P…

python—os模块、时间模块

os模块 作用&#xff1a;os模块是python标准库中的一个用于访问操作系统功能的模块&#xff0c; os模块提供了其他操作系统接口&#xff0c;可以实现跨平台访问。 使用&#xff1a; 1 . 返回操作系统类型 &#xff1a;os.name 值为&#xff1a;posix 是linux操作系统 值为&…

kotlin键值对数组_Kotlin程序检查数组是否包含给定值

kotlin键值对数组Given an array and an element, we have to check whether array contains the given element or not. 给定一个数组和一个元素&#xff0c;我们必须检查数组是否包含给定的元素。 Example: 例&#xff1a; Input:arr [34, 56, 7, 8, 21, 0, -6]element to…

enter sleep mode黑屏怎么解决_【linux】 不要再暴力关机了,讲讲我最近遇到的问题和完美解决方案...

欢迎关注我的个人公众号&#xff1a;AI蜗牛车前言结束了每天的紧张的工作&#xff0c;这两天真的有些肝。这两天打打字&#xff0c;突然感觉手指头疼起来了&#xff0c;想意识到成天打了十多个小时的键盘&#xff0c; 手指头都疲劳了 之后这两天基本上除了基本的吃睡&#xff…

重复T次的LIS的dp Codeforces Round #323 (Div. 2) D

http://codeforces.com/contest/583/problem/D 原题&#xff1a;You are given an array of positive integers a1, a2, ..., an  T of length n  T. We know that for any i > n it is true that ai  ai - n. Find the length of the longest non-decreasing …

微擎pc 导入前缀_段覆盖前缀| 8086微处理器

微擎pc 导入前缀As we already know that the effective address is calculated by appending the segment registers value and adding up the value of the respective offset. But what if we want to choose some other offset than the assigned one. 众所周知&#xff0…

python—面向对象

面向过程 面向对象&#xff1a; 面向过程&#xff1a;—侧重于怎么做&#xff1f; 1.把完成某一个需求的 所有步骤 从头到尾 逐步实现 2.根据开发要求&#xff0c;将某些功能独立的代码封装成一个又一个函数 3.最后完成的代码&#xff0c;就是顺序的调用不同的函数 特点&#…

5中bug vue_苹果官网出BUG!这些都只要一两百元

近日&#xff0c;有网友在网上反馈称&#xff0c;他发现苹果官网商城出现了BUG&#xff01;众多上千元的产品&#xff0c;BUG价只需一两百元。比如Shure MOTIV MV88 Digital立体声电容式麦克风配件。正常售价1288元&#xff0c;而BUG后的价格是235元。UBTECH Jimu Astrobot Cos…

常用压缩,解压与打包

常用压缩格式&#xff1a; .zip .zg .bz2 .tar.gz .tar.bz2.zip格式压缩zip 压缩文件名 源文件#压缩文件注&#xff1a;压缩文件名写.zip后缀是为了标记该文件的压缩类型&#xff0c;方便管理。注&#xff1a;在压缩时有压缩格式转换&#xff0c;所以当源文件很小时&#xff0c…

css禁用选中文本_使用CSS禁用文本选择突出显示

css禁用选中文本Introduction: 介绍&#xff1a; Texts are the most fundamental elements of any websites or web pages, they form the basis of the web pages or websites because if you don’t write something that you will not be able to present anything. There…

CDN加速实现—varnish

CDN介绍&#xff1a; 1 . 对cdn的理解&#xff1a; CDN的全称是&#xff08;Content Delivery Network&#xff09;&#xff0c;即内容分发网络&#xff1b;加速器&#xff0c;反向代理缓存。CDN系统能够实时的根据网络流量和各节点的连接&#xff0c;负载状况以及到用户的举例…

3dmax如何拆分模型_3dmax制作装饰柜1

大家好&#xff0c;今天我来为大家讲解一下如何利用3dmax制作装饰柜。我们需要制作装饰柜模型&#xff0c;当我们为它添加一个材质后&#xff0c;它就是这样的效果。单击创建&#xff0c;选择图形&#xff0c;对象为样条线&#xff0c;选择矩形在场景中进行创建。单击修改&…

TODO:macOS上ThinkPHP5和Semantic-UI集成

TODO&#xff1a;macOS上ThinkPHP5和Semantic-UI集成1. 全局安装 (on OSX via homebrew)Composer 是 homebrew-php 项目的一部分2. 把Xcode升级到8.1后继续安装Composer3. 使用composer创建TP5项目MWL-Dispatchcomposer create-project topthink/think MWL-Dispatch4. 配置apac…

np.expm1_JavaScript中带有示例的Math.expm1()方法

np.expm1JavaScript | Math.expm1()方法 (JavaScript | Math.expm1() Method) Math operations in JavaScript are handled using functions of math library in JavaScript. In this tutorial on Math.expm1() method, we will learn about the expm1() method and its workin…

距离传感器控制灯泡代码_生迪全彩智能 LED 灯泡体验评测

市面上大多数智能灯具无外乎智能控制&#xff0c;冷暖标准区间的简单调光&#xff0c;仅仅满足我们日常照明之外&#xff0c;似乎用处不多。如果有一款能在自己房间制造多彩氛围的灯泡就好了。这次有幸体验到了华为智能家居生态链产品生迪全彩智能 LED 灯泡&#xff0c;才发现彩…

mysql启动与关闭(手动与自动)

手动管理mysql的启动与关闭 [rootmysql ~]# service mysql start --手动启动mysqlStarting MySQL. SUCCESS![rootmysql ~]# service mysql stop --手动关闭mysql Shutting down MySQL.. SUCCESS! [rootmysql ~]# mysqld --verbose --help --查看MySQL的默认参数的具体值 如果每…