C Primer Plus(第六版)13.11 编程练习 第1题

#include <stdio.h>

#include <stdlib.h>

// 13.10-4.txt

int main()

{

int ch;

FILE *fp;

unsigned long count = 0;

char file_name30;

char str30;

printf("文件名:\n");

scanf("%s",file_name);

if ((fp = fopen(file_name, "a+")) == NULL)

{

printf("Can't open %s\n", file_name);

exit(EXIT_FAILURE);

}

printf("需要添加的信息(ctrl+z结束):");

while(scanf("%s",str) != EOF)

{

fprintf(fp, "%s", str);

}

fseek(fp, 0L, SEEK_SET);

while ((ch = getc(fp)) != EOF)

{

putc(ch,stdout);

count++;

}

fclose(fp);

printf("\nFile %s has %lu characters\n", file_name, count);

return 0;

}

相关推荐
2603_965148116 分钟前
电商选品调研:通过关键词搜索API获取市场热销商品,结合商品详情API分析竞品卖点与定价
开发语言·数据库·人工智能·python·信息可视化
xixiaoyunya1 小时前
Python 异步编程入门:用 asyncio 轻松实现并发任务
开发语言·python·php
学逆向的1 小时前
C 循环结构的执行效率分析
c语言·开发语言·数据结构·网络安全
小坏讲微服务1 小时前
刚发布一个月的JDK 27,为什么我建议你立刻升级?
java·开发语言·spring boot·spring·架构·求职招聘·springboot4
打工仔折腾 AI3 小时前
用 Dashlet 把极空间 NAS 服务入口整理成统一导航首页的实践
java·开发语言·人工智能·后端·python·rpc·ai agent 实战
MATLAB代码顾问3 小时前
Simulink PI 参数扫描与批量仿真完整 MATLAB 代码
开发语言·matlab
Want5953 小时前
Python跳动的爱心②
开发语言·python·数学建模
Navigator_Z4 小时前
LeetCode //C - 1293. Shortest Path in a Grid with Obstacles Elimination
c语言·算法·leetcode
小羊没烦恼!4 小时前
T-SQL查询进阶--理解SQL SERVER中的分区表
服务器·开发语言·前端·javascript·html
爱吃香菜的初学者5 小时前
十六.Linux——多线程(2)
linux·运维·开发语言