用fputc和fgetc操作文件的输入输出-复制文件
来源:互联网 发布:关于淘宝的故事 编辑:程序博客网 时间:2024/04/29 09:44
这段程序,先从控制台读取一段字符串到第一个文件中,然后将第一个文件的内容复制到第二个文件中。
#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){ FILE *in,*out; char filename[30]="nyist.txt",filename_copy[30]="zhengda.txt",str[50]; printf("enter filename:\n"); gets(filename);/*读入要复制的文件的文件名*/ printf("enter strings:\n"); gets(str); if((out=fopen(filename,"w"))==NULL) { printf("cannot open file!\n"); exit(0); } fputs(str,out);/*将字符串存到文件中*/ fclose(out); printf("contents have been saved in file %s\n\n",filename); printf("enter the other filename which you want to copy with:\n"); gets(filename_copy);/*读入要复制到的文件名*/ if((out=fopen(filename,"r"))==NULL) { printf("cannot open the outputfile!\n"); exit(0); } if((in=fopen(filename_copy,"w"))==NULL) { printf("cannot open the inputfile!\n"); exit(0); } while(!feof(out))/*一个字符一个字符的从第一个文件中读到第二个文件中*/ fputc(fgetc(out),in); fclose(out); fclose(in); return 0;}
0 0
- 用fputc和fgetc操作文件的输入输出-复制文件
- 库函数fopen/fgetc/fputc实现两个文件内容的复制
- linux c之用fputc和fgetc复制文件并且打印在终端
- fputc和fgetc按字符读写文件
- fgetc和fputc实现文件拷贝
- 标准I/O:分别用fgetc与fputc,fgets与fputs,fread与fwrite实现文件的复制
- 文件操作函数 C (fputc fgetc fputs fgets fscanf fprintf)
- c库文件操作——fputc(),fgetc()
- 用fgetc读文件,用fputc写文件
- 用fgetc和fputc把一个文件拷贝到另外一个文件
- C语言文件读写函数——fputc和fgetc
- C语言文件读写函数——fputc和fgetc
- C语言文件读写函数——fputc和fgetc
- fgetc和fputc的使用方法
- 标准I/O:分别用fgetc与fputc,fgets与fputs统计文件的行数
- 文件的操作3---feof函数、calloc 函数、fgetc函数、_getw函数、strcat函数、fputc函数、strstr函数
- C语言 文件操作 结构体与文件 fgetc fputc fread fwrite
- 文件中的'\0'和'\n' 与fgetc、fputc、fgets、fputs 的关系及各函数如何处理
- 数据类型计算效率,double ,int,long,short,float
- Unity3d编辑animation窗口时,如果要编辑一个Prefab的clip必须先把这个Prefab拖到Scene视图
- android项目中一些常用权限
- Flex 4中实现图形的显示和多选框的选择
- 过滤字符串中的特殊符号
- 用fputc和fgetc操作文件的输入输出-复制文件
- ORACLE的学习笔记第二天----3.30
- 英超
- 李开复:算法的力量
- struts2结合过滤器和cookie实现自动登录
- 用Qt写一个截屏工具
- 我的vim设置
- CloudTest Getting Started Guide
- poj 1131 Octal Fractions