#include <stdio.h> #include <stdlib.h>int main () {char buf[64]= "Hello word!"; /read to open file read file information output/*file *fp=fopen ("./file1", "R"), if (!FP) {perror ("File Open exception!"); Exit (-1);} Char buf[64]={"};size_t num=fread (BUF,1,63,FP);p rintf ("%d%s\n ", num, buf); fclose (FP); *///Write file Information/*file *fp2=fopen ("./file1", "w"), if (!FP2) {perror ("File Open exception!"); Exit (-1);} Char buf[64]= "Hello World"; fwrite (BUF,1,64,FP2); fclose (FP2) *///read the contents of file 1 to file *fp3=fopen ("./file1", "R") in document 2; if (!FP3) {perror ("file read exception!"); Exit (-1);} File *fp4=fopen ("./file2", "w"), if (!FP4) {perror ("file read exception!"); Exit (-1);} while (1) {size_t num=fread (BUF,1,20,FP3), if (num<=0) {break;} Fwrite (BUF,1,NUM,FP4);} Fclose (FP3); fclose (FP4); return 0;}
Relive the C language--file manipulation