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;

}

相关推荐
dvvvvvw17 小时前
调用函数两点间的距离.c
c语言
胡萝卜3.021 小时前
掌握C++ map:高效键值对操作指南
开发语言·数据结构·c++·人工智能·map
电子_咸鱼21 小时前
【STL string 全解析:接口详解、测试实战与模拟实现】
开发语言·c++·vscode·python·算法·leetcode
哈茶真的c1 天前
【书籍心得】左耳听风:传奇程序员练级攻略
java·c语言·python·go
沐知全栈开发1 天前
ionic 选项卡栏操作详解
开发语言
曹牧1 天前
C#中,#region和#endregion
开发语言·c#
顾安r1 天前
11.22 脚本打包APP 排错指南
linux·服务器·开发语言·前端·flask
蒙小萌19931 天前
Swift UIKit MVVM + RxSwift Development Rules
开发语言·prompt·swift·rxswift
Z***25801 天前
Java爬虫框架
java·开发语言·爬虫
王光环1 天前
union用法
c语言·union