当前位置:网站首页>6-7 file read / write operation
6-7 file read / write operation
2022-06-11 17:37:00 【Tomatoes_ Menon】
Write function , Read in by line from the given input text file , And write to the given output file by line . requirement :1) Remove leading spaces or tabs from each line .2) Add line number before each line .
Function interface definition :
void fileRW(FILE *fin,FILE *fout); among fin and fout All parameters passed in by the user , Are the pointers to the read in file and the output file respectively ( Opened as required ).
Sample referee test procedure :
#include <stdio.h>
void fileRW(FILE *fin,FILE *fout);
int main(){
char fname[20];gets(fname);
FILE *fpr=fopen(fname,"r");
FILE *fpw=fopen("file2.txt","w");
fileRW(fpr,fpw);
fclose(fpr);fclose(fpw);
return 0;
}
/* Please fill in the answer here */sample input :
Input file name :file1.cpp, The content is :
void fileW(){
FILE *fp1=fopen("myfile.data","w");
int i=123;float x=3.14159;
fprintf(fp1,"%d,%5d,%5.3f\n",i,-i,x);
fprintf(stdout,"%d,%5d,%5.3f\n",i,-i,x);
fclose(fp1);
}
sample output :
file :file2.txt, The content is :
1:void fileW(){
2:FILE *fp1=fopen("myfile.data","w");
3:int i=123;float x=3.14159;
4:fprintf(fp1,"%d,%5d,%5.3f\n",i,-i,x);
5:fprintf(stdout,"%d,%5d,%5.3f\n",i,-i,x);
6:fclose(fp1);
7:}
void fileRW(FILE *fin,FILE *fout)
{
char str;
int i=1,j=1;
do
{
str = fgetc(fin);//str Used to store the read string
if(i==j && str!=EOF)
{
fprintf(fout,"%d:",j++);//j Is the number of lines in the input file
while(str==' ' || str == '\t')
str = fgetc(fin);
}
if(str == '\n')
i++;//i Is the number of lines in the output file
if(str==EOF)
break;
fputc(str,fout);
}
while(1);// Read to the end of the file and return EOF It will end the cycle
}
边栏推荐
- Dynamic: capturing network dynamics using dynamic graph representation learning
- 6-2 多个整数的逆序输出-递归
- Authing biweekly news: online application market (5.10-5.22)
- Authing Share|理解 SAML2 协议
- 开源项目那么多,这次带你了解个版本的区别,明白alpha版、beta版、rc版是什么意思
- 合并两个有序链表---2022/02/24
- Foreach traverses collections and collection containers
- Don't you understand the design and principle of thread pool? Break it up and crush it. I'll teach you how to design the thread pool
- 信息安全数学基础 Chapter 1——整除
- There are so many open source projects. This time, I'll show you the differences between different versions and understand the meaning of alpha version, beta version and RC version
猜你喜欢

Service learning notes 02- actual combat startservice and bindservice

Bentley 使用 Authing 快速实现应用系统与身份的集成

Authing biweekly news: authing forum launched (4.25-5.8)

端口规划与APJ
![[online problem] timeout waiting for connection from pool](/img/f0/7e8444ed7d0921b98d5e998e274bc8.png)
[online problem] timeout waiting for connection from pool

Biden ordered to enforce the zero trust structure

05_特征工程—降维

Authoring share | understanding saml2 protocol

Port planning and APJ

你还不懂线程池的设计及原理吗?掰开揉碎了教你设计线程池
随机推荐
ADB command learning notes
6-8 有结构文件的读写1
R语言 mice包 Error in terms.formula(tmp, simplify = TRUE) : ExtractVars里的模型公式不对
[online problem] timeout waiting for connection from pool
How does Sister Feng change to ice?
ArrayList collection, object array
tidb-cdc同步mysql没有的特性到mysql时的处理
R language mice package error in terms Formula (TMP, simplify = true): the model formula in extractvars is incorrect
6-5 统计单词数量(文件)(*)
Hands on deep learning - multiple input and output channels in the convolution layer
Automated testing selenium
Kubernetes deploys elk and collects container logs using filebeat
which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mod
There are so many open source projects. This time, I'll show you the differences between different versions and understand the meaning of alpha version, beta version and RC version
使用exe4j 将.jar文件打包为.exe文件
论文阅读 dyngraph2vec: Capturing Network Dynamics using Dynamic Graph Representation Learning
开源项目那么多,这次带你了解个版本的区别,明白alpha版、beta版、rc版是什么意思
Service learning notes 01 start method and life cycle
tidb-ddl的速度的调整
MFSR:一种新的推荐系统多级模糊相似度量