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;

}

相关推荐
xxl大卡17 小时前
Redis 主从复制与哨兵模式
java·开发语言
嗝o゚17 小时前
CANN pyasc 工具——Python 接口的算子开发
开发语言·python·cann·pyasc
楼田莉子17 小时前
C++20现代特性:概念与约束
开发语言·c++·后端·学习·c++20
重生之小比特17 小时前
【初阶C++】入门基础
开发语言·c++
程序leo源17 小时前
Qt界面优化详解
linux·c语言·开发语言·c++·qt·c#
沙糖桔4517 小时前
多端协同系统中共享资源分配的状态一致性设计
java·开发语言
csbysj202017 小时前
SQLite 删除表
开发语言
咔咔库奇17 小时前
js-执行上下文
开发语言·前端·javascript
Land032917 小时前
RPA替代方案:离线部署与Python扩展实战
开发语言·python·rpa
郝学胜-神的一滴17 小时前
Qt 高级开发 017:中文乱码
开发语言·c++·qt·程序人生·用户界面