实现文件的读写操作举例
来源:互联网 发布:mac finder 打开路径 编辑:程序博客网 时间:2024/04/28 12:44
手动创建两个文本文件text1.txt,text2.txt,要求编程创建text3.txt,实现text1.txt和text2.txt文件中出去begin,end 对应数据相加,三个文本内容如下:
text1.txt:
begin 10 11 12 20 21 22 30 31 32 end
text2.txt:
begin 15 16 17 25 26 27 35 36 37 end
text3.txt:
begin 2 27 29 45 47 49 65 67 69 end
代码如下:
#include<stdio.h>#include<stdlib.h>#include<sys/types.h>#include<sys/stat.h>#include<fcntl.h>int main(){FILE * fp1;FILE * fp2;FILE * fp3;int c1,c2,c3; fp1 = fopen("text1.txt","r"); fp2 = fopen("text2.txt","r");fp3 = fopen("text3.txt","w+");while(((c1 = fgetc(fp1)) != EOF) && ((c2 = fgetc(fp2)) != EOF)){if(((c1 >= 'a') && (c2 <= 'z')) || ((c1 == ' ') &&(c2 == ' '))){c3 = c1; fputc(c3,fp3);}else{ c3 = (c1 - '0') + (c2 - '0') + '0';fputc(c3,fp3);}}close(fp1);close(fp2);close(fp3);}
0 0
- 实现文件的读写操作举例
- 简单的文件读写函数举例
- iphone实现文件的读写操作
- iphone实现文件的读写操作
- IOS 文件读写操作的实现
- Python实现Excel文件的读写操作
- 文件的读写操作
- 文件的读写操作
- 文件的读写操作
- 文件的读写操作
- 文件的读写操作
- 读写文件的操作
- 文件的读写操作
- 文件的读写操作
- 文件的读写操作
- 文件的读写操作
- 【文件的读写操作】
- 文件的读写操作
- AdaBoost算法详解
- hduoj 1284详细解题,推荐
- 如何查看JSTL中自带的TLD文件
- 【VSCode】Windows下VSCode编译调试c/c++
- 《恋狱》
- 实现文件的读写操作举例
- 重修Java——运算符
- 5秒让你的View变3D,ThreeDLayout使用和实现
- 英文名字的昵称(亲切的叫法)
- 杭电oj编码2013
- 堆和栈的区别和联系
- MyBatis SQL在xml中,处理大于小于号的方法
- 天线的基本原理和概念
- php实现等比例生成图片缩略图不失真