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_name[30];

char str[30];

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;

}

相关推荐
LawrenceLan5 小时前
Flutter 零基础入门(十一):空安全(Null Safety)基础
开发语言·flutter·dart
txinyu的博客6 小时前
解析业务层的key冲突问题
开发语言·c++·分布式
码不停蹄Zzz6 小时前
C语言第1章
c语言·开发语言
行者967 小时前
Flutter跨平台开发在OpenHarmony上的评分组件实现与优化
开发语言·flutter·harmonyos·鸿蒙
阿蒙Amon7 小时前
C#每日面试题-Array和ArrayList的区别
java·开发语言·c#
666HZ6667 小时前
数据结构2.0 线性表
c语言·数据结构·算法
SmartRadio7 小时前
ESP32添加修改蓝牙名称和获取蓝牙连接状态的AT命令-完整UART BLE服务功能后的完整`main.c`代码
c语言·开发语言·c++·esp32·ble
且去填词7 小时前
Go 语言的“反叛”——为什么少即是多?
开发语言·后端·面试·go
知乎的哥廷根数学学派8 小时前
基于生成对抗U-Net混合架构的隧道衬砌缺陷地质雷达数据智能反演与成像方法(以模拟信号为例,Pytorch)
开发语言·人工智能·pytorch·python·深度学习·机器学习
yeziyfx8 小时前
kotlin中 ?:的用法
android·开发语言·kotlin