文件操作主要函数Word文档下载推荐.docx

上传人:b****5 文档编号:19376437 上传时间:2023-01-05 格式:DOCX 页数:27 大小:25.56KB
下载 相关 举报
文件操作主要函数Word文档下载推荐.docx_第1页
第1页 / 共27页
文件操作主要函数Word文档下载推荐.docx_第2页
第2页 / 共27页
文件操作主要函数Word文档下载推荐.docx_第3页
第3页 / 共27页
文件操作主要函数Word文档下载推荐.docx_第4页
第4页 / 共27页
文件操作主要函数Word文档下载推荐.docx_第5页
第5页 / 共27页
点击查看更多>>
下载资源
资源描述

文件操作主要函数Word文档下载推荐.docx

《文件操作主要函数Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《文件操作主要函数Word文档下载推荐.docx(27页珍藏版)》请在冰豆网上搜索。

文件操作主要函数Word文档下载推荐.docx

Libraries

LIBC.LIB

Singlethreadstaticlibrary,retailversion

LIBCMT.LIB

Multithreadstaticlibrary,retailversion

MSVCRT.LIB

ImportlibraryforMSVCRT.DLL,retailversion

Thec,n,andtmodeoptionsareMicrosoftextensionsforfopenand_fdopenandshouldnotbeusedwhereANSIportabilityisdesired.

ReturnValue

Eachofthesefunctionsreturnsapointertotheopenfile.Anullpointervalueindicatesanerror.

Parameters

filename

Filename

mode

Typeofaccesspermitted

Remarks

Thefopenfunctionopensthefilespecifiedbyfilename._wfopenisawide-characterversionoffopen;

theargumentsto_wfopenarewide-characterstrings._wfopenandfopenbehaveidenticallyotherwise.

Generic-TextRoutineMappings

TCHAR.HRoutine

_UNICODE&

_MBCSNotDefined

_MBCSDefined

_UNICODEDefined

_tfopen

Thecharacterstringmodespecifiesthetypeofaccessrequestedforthefile,asfollows:

"

r"

Opensforreading.Ifthefiledoesnotexistorcannotbefound,thefopencallfails.

w"

Opensanemptyfileforwriting.Ifthegivenfileexists,itscontentsaredestroyed.

a"

Opensforwritingattheendofthefile(appending)withoutremovingtheEOFmarkerbeforewritingnewdatatothefile;

createsthefilefirstifitdoesn’texist.

r+"

Opensforbothreadingandwriting.(Thefilemustexist.)

w+"

Opensanemptyfileforbothreadingandwriting.Ifthegivenfileexists,itscontentsaredestroyed.

a+"

Opensforreadingandappending;

theappendingoperationincludestheremovaloftheEOFmarkerbeforenewdataiswrittentothefileandtheEOFmarkerisrestoredafterwritingiscomplete;

Whenafileisopenedwiththe"

or"

accesstype,allwriteoperationsoccurattheendofthefile.Thefilepointercanberepositionedusingfseekorrewind,butisalwaysmovedbacktotheendofthefilebeforeanywriteoperationiscarriedout.Thus,existingdatacannotbeoverwritten.

The"

modedoesnotremovetheEOFmarkerbeforeappendingtothefile.Afterappendinghasoccurred,theMS-DOSTYPEcommandonlyshowsdatauptotheoriginalEOFmarkerandnotanydataappendedtothefile.The"

modedoesremovetheEOFmarkerbeforeappendingtothefile.Afterappending,theMS-DOSTYPEcommandshowsalldatainthefile.The"

modeisrequiredforappendingtoastreamfilethatisterminatedwiththeCTRL+ZEOFmarker.

Whenthe"

"

or"

accesstypeisspecified,bothreadingandwritingareallowed(thefileissaidtobeopenfor“update”).However,whenyouswitchbetweenreadingandwriting,theremustbeaninterveningfflush,fsetpos,fseek,orrewindoperation.Thecurrentpositioncanbespecifiedforthefsetposorfseekoperation,ifdesired.

Inadditiontotheabovevalues,thefollowingcharacterscanbeincludedinmodetospecifythetranslationmodefornewlinecharacters:

t

Openintext(translated)mode.Inthismode,CTRL+Zisinterpretedasanend-of-filecharacteroninput.Infilesopenedforreading/writingwith"

fopenchecksforaCTRL+Zattheendofthefileandremovesit,ifpossible.ThisisdonebecauseusingfseekandftelltomovewithinafilethatendswithaCTRL+Z,maycausefseektobehaveimproperlyneartheendofthefile.

Also,intextmode,carriagereturn–linefeedcombinationsaretranslatedintosinglelinefeedsoninput,andlinefeedcharactersaretranslatedtocarriagereturn–linefeedcombinationsonoutput.WhenaUnicodestream-I/Ofunctionoperatesintextmode(thedefault),thesourceordestinationstreamisassumedtobeasequenceofmultibytecharacters.Therefore,theUnicodestream-inputfunctionsconvertmultibytecharacterstowidecharacters(asifbyacalltothembtowcfunction).Forthesamereason,theUnicodestream-outputfunctionsconvertwidecharacterstomultibytecharacters(asifbyacalltothewctombfunction).

b

Openinbinary(untranslated)mode;

translationsinvolvingcarriage-returnandlinefeedcharactersaresuppressed.

Iftorbisnotgiveninmode,thedefaulttranslationmodeisdefinedbytheglobalvariable_fmode.Iftorbisprefixedtotheargument,thefunctionfailsandreturnsNULL.

FormoreinformationaboutusingtextandbinarymodesinUnicodeandmultibytestream-I/O,seeTextandBinaryModeFileI/OandUnicodeStreamI/OinTextandBinaryModes.

c

Enablethecommitflagfortheassociatedfilenamesothatthecontentsofthefilebufferarewrittendirectlytodiskifeitherfflushor_flushalliscalled.

n

Resetthecommitflagfortheassociatedfilenameto“no-commit.”Thisisthedefault.ItalsooverridestheglobalcommitflagifyoulinkyourprogramwithCOMMODE.OBJ.Theglobalcommitflagdefaultis“no-commit”unlessyouexplicitlylinkyourprogramwithCOMMODE.OBJ.

Validcharactersforthemodestringusedinfopenand_fdopencorrespondtooflagargumentsusedin_openand_sopen,asfollows.

CharactersinmodeString

EquivalentoflagValuefor_open/_sopen

a

_O_WRONLY|_O_APPEND(usually_O_WRONLY|_O_CREAT|_O_APPEND)

a+

_O_RDWR|_O_APPEND(usually_O_RDWR|_O_APPEND|_O_CREAT)

r

_O_RDONLY

r+

_O_RDWR

w

_O_WRONLY(usually_O_WRONLY|_O_CREAT|_O_TRUNC)

w+

_O_RDWR(usually_O_RDWR|_O_CREAT|_O_TRUNC)

_O_BINARY

_O_TEXT

None

Example

/*FOPEN.C:

Thisprogramopensfilesnamed"

data"

*and"

data2"

.Itusesfclosetoclose"

and

*_fclosealltocloseallremainingfiles.

*/

#include<

FILE*stream,*stream2;

voidmain(void)

{

intnumclosed;

/*Openforread(willfailiffile"

doesnotexist)*/

if((stream=fopen("

))==NULL)

printf("

Thefile'

data'

wasnotopened\n"

);

else

wasopened\n"

/*Openforwrite*/

if((stream2=fopen("

data2'

/*Closestream*/

if(fclose(stream))

wasnotclosed\n"

/*Allotherfilesareclosed:

numclosed=_fcloseall();

Numberoffilesclosedby_fcloseall:

%u\n"

numclosed);

}

Output

wasopened

1

StreamI/ORoutines

SeeAlso 

 

fclose,_fdopen,ferror,_fileno,freopen,_open,_setmode

fclose,_fcloseall

Closesastream(fclose)orclosesallopenstreams(_fcloseall).

intfclose(FILE*stream);

int_fcloseall(void);

fclose

_fcloseall

fclosereturns0ifthestreamissuccessfullyclosed._fcloseallreturnsthetotalnumberofstreamsclosed.BothfunctionsreturnEOFtoindicateanerror.

Parameter

stream

PointertoFILEstructure

Thefclosefunctionclosesstream._fcloseallclosesallopenstreamsexceptstdin,stdout,stderr(and,inMS-DOS®

_stdauxand_stdprn).Italsoclosesanddeletesanytemporaryfilescreatedbytmpfile.Inbothfunctions,allbuffersassociatedwiththestreamareflushedpriortoclosing.System-allocatedbuffersarereleasedwhenthestreamisclosed.Buffersassignedbytheuserwithsetbufandsetvbufarenotautomaticallyreleased.

_close,_fdopen,fflush,fopen,freopen

fwrite

Writesdatatoastream.

size_tfwrite(constvoid*buffer,size_tsize,size_tcount,FILE*stream);

fwritereturnsthenumberoffullitemsactuallywritten,whichmaybelessthancountifanerroroccurs.Also,ifanerroroccurs,thefile-positionindicatorcannotbedetermined.

buffer

Pointertodatatobewritten

size

Itemsizeinbytes

count

Maximumnumberofitemstobewritten

Thefwritefunct

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 农林牧渔 > 畜牧兽医

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1