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;

}

相关推荐
leo__5201 小时前
IEC 104 协议 C 语言实现
c语言·数据库
CHANG_THE_WORLD1 小时前
python 批量终止进程exe
开发语言·python
古城小栈1 小时前
从 cargo-whero 库中,找到提升 rust 的契机
开发语言·后端·rust
Gary Studio2 小时前
安卓HAL C++基础-智能指针
开发语言·c++
啧不应该啊3 小时前
Day1 Python 与 C 的类型区别
c语言·开发语言
cen__y3 小时前
Linux07(信号01)
linux·运维·服务器·c语言·开发语言
xingpanvip3 小时前
星盘接口开发文档:星相日历接口指南
android·开发语言·前端·css·php·lua
guygg883 小时前
基于遗传算法的双层规划模型求解MATLAB实现
开发语言·matlab
凯瑟琳.奥古斯特4 小时前
SQLAlchemy核心功能解析
开发语言·python·flask
卷Java4 小时前
GPTQ vs AWQ vs GGUF:模型量化工具横向测评
开发语言·windows·python