1122
来源:互联网 发布:籼米和粳米知乎 编辑:程序博客网 时间:2024/06/12 21:00
建立两个文件text1.txt和text2.txt
text1.txt内容:
begin
15 25 35
25 35 45
55 45 66
end
text2.txt内容
begin
25 35 45
14 14 15
25 25 22
end
将两个文件中的数相加
#include <stdio.h>#include <stdlib.h>
#include <string.h>
int main()
{
FILE *text1;
FILE *text2;
FILE *text3;
char ch1;
char ch2;
char ch3;
int num1;
int num2;
int sum;
//同时读取
if((text1=fopen("text1.txt","r")) == NULL)
{
printf("cannot open file strike any key exit!\n");
exit(1);
}
if((text2=fopen("text2.txt","r")) == NULL)
{
printf("cannot open file strike any key exit!\n");
exit(1);
}
if((text3=fopen("text3.txt","w+")) == NULL)
{
printf("cannot open file strike any key exit!\n");
exit(1);
}
while((ch1=fgetc(text1))!=EOF,(ch2=fgetc(text2))!=EOF)
{
if((ch1>'9'||ch1<'0')&&(ch2>'9'||ch2<'0'))
{
fputc(ch1,text3);
}
else
{
num1 = (ch1 - '0')*10 + fgetc(text1) - '0';
num2 = (ch2 - '0')*10 + fgetc(text2) - '0';
sum = num1 + num2;
fputc((sum/10 +'0'),text3);
fputc((sum%10 +'0'),text3);
}
}
fclose(text1);
fclose(text2);
fclose(text3);
return 0;
}
0 0
- 1122
- 1122
- 1122
- 1122
- 1122
- 1122
- ZJU 1122
- poj 1122
- ZOJ-1122
- 1122 -- 排列
- poj 1122
- 练习1122
- PAT 1122
- ZOJ 1122 Clock
- sicily 1122 Prerequisites?
- poj 1122 dijkstra
- 题目1122: 找x
- poj 1122最短路
- OneProxy简明使用手册
- java设计模式之代理模式
- Vivado HLS IP-XACT快速创建AXI总线IP(PWM)z
- 基于Token的WEB后台认证机制
- Thrift学习笔记(5)--Thrift 半同步半异步的服务端模型
- 1122
- UE4的UI制作流程
- Guice 依赖注入
- 数据分析及运用(一)
- UISwitch 默认大小
- Centos6.5 安装mysql
- Mybatis框架中Mapper文件传值参数获取。【Mybatis】
- windows NT的意义和各个版本
- 无法打开到sql server的连接 错误2