linux c之用fputc和fgetc复制文件并且打印在终端

112 阅读1分钟

1、fputs和fgetc相关函数解释

1、字符的输出

 

#include<stdio.h>
int getc(FILE *fp)
int fgetc(FILE *fp)
int getchar(vaid)

 


3个函数若成功返回读入的字符值,若出错或则到末尾返回EOF,EOF为常量是-1

 

 

 

 

 

 

2、字符的输入

 

#include<stdio.h>
int putc(int c, FILE *fp)
int fputc(int c, FILE *fp)
int putchar(int c)

 

 


3个函数返回,若成功则为c,若出错返回EOF

 

 

 

 

 

 

 

 

 

 

 

2、代码复制文件内容并且终端打印的实现

我需要把hello.txt里面的内容复制到test.txt文件去,并把内容打印出来

 

#include<stdio.h>
#include<stdlib.h>

#define  PATH1 "/home/chenyu/Desktop/linux/hello.txt"
#define  PATH2 "/home/chenyu/Desktop/linux/test.txt&#