C language Fgetc () and FPUTC ()

Source: Internet
Author: User
Tags erro

//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 ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.