//fgetc () and FPUTC ()#define_crt_secure_no_warnings#include<stdio.h>#include<stdlib.h>#include<string.h>//Text Write fileintWriteword (Const Char*path,Const Char*Pword) { intErro_msg =0; inti =0; if(Path = =NULL) {erro_msg=1; printf ("path==null Erro msg:%d\n", erro_msg); returnerro_msg; } if(Pword = =NULL) {erro_msg=2; printf ("pword==null Erro msg:%d\n", erro_msg); returnerro_msg; } //Defining file PointersFILE *fpw=NULL; //Open FileFPW = fopen (Path,"W");//W Open Write-only file, if the file exists, then the file length is zeroed, that is, the contents of the file disappears, if the file does not exist the file is created//determine if the file is open successfully if(fpw==NULL) {erro_msg=1; printf ("File open failed Fpw==null erro msg:%d\n", erro_msg); returnerro_msg; } //Start writing Files for(i =0; I < (int) strlen (Pword) +1; i++) {FPUTC (pword[i], FPW); } //fputs (Pword, FPW); //Close File if(fpw!=NULL) {fclose (FPW); } returnerro_msg;}//file Read FileintReadtxt (Const Char*path,Char*pout)//Two-level pointer output{ intErro_msg =0; if(path==NULL) {erro_msg=1; printf ("path==null Erro msg:%d\n", erro_msg); returnerro_msg; } if(Pout = =NULL) {erro_msg=2; printf ("pout==null Erro msg:%d\n", erro_msg); returnerro_msg; } //Defining file PointersFILE *PFR =NULL; //Open FilePFR = fopen (Path,"R"); if(pfr==NULL) {erro_msg=3; printf ("pfr==null erro msg:%d, file path:%s\n", erro_msg, Path); returnerro_msg; } //Start reading Files intindex =0; //Read the file while(!feof (PFR)) {//feof () returns a value other than 0 if the file ends, otherwise 0//memset (pout, 0, sizeof (char) *200);pout[index++] =fgetc (PFR); } Pout[index]=' /'; returnerro_msg;}voidMain () {//Defining file Paths Char*path ="e:\\test\\cwordtest\\";//applies to window only Char*path1 ="E:/test/cwordtest/a1.txt"; Writeword (path1,"Asfasdfasdgafdsgadf\r\nasdfadsadf\r\ndsafgshfetgrhet"); //1. Define the file cache array Charbufarr[ $] = {0 }; Readtxt (path1, Bufarr); printf ("%s\n", Bufarr); System ("Pause");}
C language Fgetc () and FPUTC ()