0% found this document useful (0 votes)
23 views

C File Handling

Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
23 views

C File Handling

Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 7
Nove: FILES “7 NK Pile conetste of no-of ‘records, klhen one Opend afte “BE oPevSHfone that ave to be performed on ‘he fle Mrugh be spectfeeg 4.6 ead, wife. Bppend , “PW use a tle 4 essential optfons must be performed A. Declaring ale painter Variable , 2 open a file Ustog & open Suntan : 3. Procese he Pe. . “close the le using 4 clante Lunesta. oa Declare: a fle pufater wayfagle “he type OP Ple thay % We Pe Used much be _specetny :TB8.can be ACCompliched by USng ple Potter Vavlabe whith Pints Yo shrucluretyy Mle. Syrtare FILE xtps 2 open a file Ux, Syntax: ‘ fe = pen lene ” maser the NAME of the Me to be oy vaviable Which & a val 9-f open skneHon & Fenel udith the help of Fle potter Fa file the mode Ihfch evets be used? 8 Rle must be specthed, Modes € > open aroet le 4, Ye Ww Creat a text fle % acting wring a-y append a sett He Scanned with CamScanner Th=> open a Stivary tle for reading el Wb > create a brary fle for witting Ab — append a Bary {le Way Open a tert file “or yead and unte Wy create a tex tle oy ead and wife 5 Append a-ent file Lor Tead and witie Hb open a inary le Yor read and untie b= Clete a ireny file for Yea and wie SED eppend a rary Mle tyr tead and whe. py PYOCESS the 4Ple @ Gp Procescfng the {le can be copfed Stam one le to mother Cov), ding Aome programming changes . H. Close the Jple usthg felace inctong Auer com pleting the’ Process onthe fle ~ne $Ple must be closes using Pclosec 5 un ofan. Symtar? close CPpds te WAP 40 count numberof chavaders - number of vootds, adnumber ‘of tres Gna Sele. AE Prckucte K51d% bs meat ¢ i ‘ FILE xfs Chay Plename Ctoo)s xin , Gat Charechers , words 1 Anes + . Char ch? pith CS entey any Saved Phe): SeAMF OMS" | Menem, ys Pp =Popen CfPlename By": F (fp = = Nun 2 Print (“there % nocuch MH.) 3 Scanned with CamScanner Characters = words = Ines 0 a Coh= #geie ofp) = OF Chavactes4 4 4 ches "\n' lt oh = Koess ye SEC chee Wene en \e! Weh= woyass4 3 44 (cheweaciers 70) i Words + 5 Afnest+ $ 0) Sw Wene Se) pratt C’tetal chavatters 2%u", " crestacters)+ Pinte Cheotal Mines = yd! ines) + 7) PMelfc total words H% a", woras)§ c ee Bihary flee Tee operations pevfowmed on Wirany file %e afaflarty tert le. When a Ble % open must be deGittes as Fete or) binary ante CBA bE done uty i4nc help Of Mackes or the 4Ple. “Sle wr copfng Winery dPle Frto ansther fle AS allows step 4% open “the tet tile for Yeading $n Wray mole Step 2 open the destination Mle Yor uniting fh oanyrek, rend the charadas of source ile, when ‘a fle fe open at ine bedinfing of Ane file. f step uz the Junction feaPcy tratfeates” thar cine end of ~ ie aprcowce Mle ac bees, reached then those pom the les. Stepcs Bt end of *we fle has not be veached vafre “he chayacteys yo the destination fle and repeat Step 3. step ¢ Scanned with CamScanner WA Br binary fle yo gram for coping one Lple 4o another ffl + At fnclude LStdfo.h7 mafnt) ae ve wsonie 1” Seasnalton char ch, sourcel3o], destfy avon [sods Prat Center the name of felelodors ws Be Csourced + cOuhee=Popen (source, “vb! ):, 4 Cedice = = NULL) 3 » PROMO Pete cannot OPED?! 3 Phinit (emer destination £1e" 12 ges Cdest? nation) * eee on CAeSnayven wba? TH Cdestidefone = NUNS) 2 Felose coparteys Prfnif (tle cannot opens a iene 4 gele Csatnees) $= €OF) Arde Con , dest®eton)! paintt successfully copfed’): Fatose coerce, Sttoce CdeiPaatfony? 3 Sequentfl versus Random Access oles, j Scanned with CamScanner N } OP Sequemtfa) VeISUS Random Access fles « f Every open Atle has an associated sele Potter Gade | Cursor). Wh When vead and wntic operailfons “takes place 3 fale | “hE poshfn ndPeesloy always at tne befgfng of he fle, | When A new Wle g% open me potfon Indtettor fe at -tne beging . then an exfeiing -Ple & open. the postion indfrtor WS aAlane end -he Wle are called seguentfal fle, Random accese Ples¢ Random access fole fo used Control “ne Position Ind featoy ‘randomly St means we can cet =the postifon tndfeator gny Where do a fle. THES can te Achfevet by using three fumes A- fee o5 2+ Prewfaat > 3 #ret c9 A. Fsccnc ) 4 By OSG FseckED weean cet tre pasttibn RndPeatey any where Pn a fle. The distance -that the pottfon Indator & to move fs n if IN bytes: we eg ae orfg?n Specfifes the postftn indfeaturat | “he Starfing pdint- symar ¥ fot seek CFILEFP long odfcet » tnt ovfgfa + €13 Sot Fscee CHE xt, 4, 02 & Fiwese ave thee values of ovtgtin & seek-sex o YH Moves Ane indPeettor Jrym the beging of ane fle. & Seek-sets. moves the indfeetioy from the Curren! posttfon. H) seek-sei a. BWmoves the &ndfeator ty the end oftne fle. a . Scanned with CamScanner ¥ ria | 2. FseuXnd ©) .£ “Ws. dunctfon Fused 4p place “the Poston Sindfcator trom -the curred! postifon -i0 the Slaytthg- potion , B Atel Cy) Brteused Wo sel tne curren} postiyon ofa poston Fndleatoy - EM T FILE MANGEMENT. Deleting and venanfing operations areialso Assoctted wh Arle management. “C’% stantara Rbvary contains “ne functions for deleting Ana “erramng « ete Ne Pele Ne eee ee ee et ae Stsvary funct ~fon wemove 6). Symtax g ' Temove ¢frlename)s ’ CondPifone for removing a fle ¢ A+ S¥le fethe pointer to tre Name of the ole 40 be deleted. 2. the pre—condtion % that-the le must be ETfste 2 Tre le must notbe open. id Ap to delete a Mle. HE Pnclude 4 S4dPo. hy ABN) BD ene a Sorat et 2033 PATOL ( enter a $Ple 40 delete") § Scan$-c9, 6" paves PE Cremove cette = =o) 2 PAA (Efe Yemove a” ys ese Prot CO evo? i Scanned with CamScanner for the ‘Bename afile € We can vename a Lele" exfsting ie, Symtar4 yename Cord fPle i neurfele) Condtafons 4o vename a ffle '£ He -the both flees muct be on came dick. 2. We function Yelurn ‘Rew! On Success Zand “Lt! on fattune, 3 tHe new Fle must not-be » exfel- WeoAP forarename fun ctfon . att Prelude cetdfo. hy mane 9 i Chay old name C20) Char newram (20]%, printf C enter oldfPle game ys Scant (“ez,9" “the old Hle must berg, olanamey, , Prk CY enter “new APlename"): Scand (ap 0!) newnameys | | “TE Crrereme Coaname, newneme) =O) 2 prtnre CMsuccesssulty renamed") else PAME Cr evros" Ds Scanned with CamScanner

You might also like