 files:
FILE *fInput = fopen("input.txt", "r");
int ch; /* need an int to hold EOF */

for (;;)
{
    ch = fgetc(fInput);
    if (ch == EOF) break;

   ...
}

In addition, you may need to read up on file pointer concept. For example, after reading the remainder of src, you fseek() forward, and skip some more characters before you copy data to f2. Essentially, you read m, read or (with fgets() - and into an unallocated buffer s1 that would go ka-boom on you some time in the near future), skip 2 more characters (now your pointer is at last n of "morning"), copy "ng" into f2, try to write EOF to f2 in this loop (hence the above pattern for reading until EOF), seek two characters back (which may fail once you reach EOF, my C file functions are a bit rusty these days), write "even" to f1 (which should, if I am wrong about seek after EOF, set input file to "mornieven", and not change it if I am correct). In summary, I don't think the code does what you intend it to do.
I would recommend building up your function. Each one of the following can be written as a program that you should test and finish before going to next step:

read the file safely, and print it out
detect the contents of src, and print the rest of input
save the rest of the input to second file instead of printing
replace src with dest in first file, and ignore the rest (since you open input file with 'rw', this will truncate the rest of input). You may need to do an fseek() to clear the EOF status. Also look at ftell() to record a position that you can jump back to using fseek()
finally, copy in everything you have saved to second file after replacing src with dest (no need to close f1 here. But it is better to open f2 as write, close after copy from first file, and reopen as read to perform the copy back to f1).

In addition, when you need a buffer (such as s1), just use a large enough array for now, but look into malloc() and free() functions to perform dynamic memory
files: 
 FILE * fInput = fopen("input.txt ", " r "); 
 int ch; / * need an int to hold EOF * / 

 for (; ;) 
 { 
     ch = fgetc(fInput); 
     if (ch = = EOF) rupture; 

   ... 
 } 

 In accession, you may need to read up on file pointer concept. For exemplar, after reading the remainder of src, you fseek () fore, and decamp some more characters before you imitate data to f2. Essentially, you understand m, read or (with fgets () - and into an unallocated buffer s1 that would run ka - boom on you some time in the near future), skip 2 more character (now your pointer is at last normality of " morning "), copy " ng " into f2, try to write EOF to f2 in this cringle (hence the above pattern for reading until EOF), seek two characters back (which may fail once you strive EOF, my C file functions are a bit rusty these days), write " even " to f1 (which should, if I am wrong about seek after EOF, set input file to " mornieven ", and not change it if I am correct). In summary, I don't think the code does what you intend it to do. 
 I would recommend building up your affair. Each one of the following can be written as a course of study that you should screen and finish before going to next dance step: 

 read the file safely, and print it out 
 detect the contents of src, and print the rest of input 
 write the rest of the input to second file instead of printing 
 replace src with five hundred in first file, and ignore the rest (since you open input file with' rw', this will truncate the rest of input). You may necessitate to do an fseek () to clear the EOF status. Also look at ftell () to read a position that you can jump back to using fseek () 
 ultimately, copy in everything you have saved to second file after replacing src with dest (no indigence to close f1 here. But it is dependable to open f2 as write, near after copy from inaugural file, and reopen as read to do the copy back to f1). 

 In addition, when you necessitate a buffer (such as s1), just practice a large enough array for now, but look into malloc () and free () functions to perform dynamic memory
 fipes:
FILE *fInput = fopen("inpmt.txt", "r");
int ch; /* ngee an iit to hkld EOF */

wor (;;)
{
    ch = fgetc(fInput);
    ih (ch == EOF) break;

   ...
}

In addition, yuu may nevd to reae up in file pomhter cokeept. Rlr eranple, after reacing the ramainder of srw, hob fseek() forward, and skip some more craractets before you coky daua eo f2. Vswentially, you read m, read or (sith fgtts() - and into an umallocated buffer s1 that wluld go ka-boom on you dome time ib thq near future), skip 2 mort eharacters (how your pointer is at last n ow "moruing"), copy "nt" untl f2, try to wcite EJF to f2 in tmps loop (hence yhe above pattcrn fmr eeading until EOF), seen two characters bwck (which mcy fail once you reacy WOF, mi C fhle wyncgiohs ade a blt custy these days), write "even" to f1 (which shpuje, if I am wrohg abott seek after EOF, set input file to "mornitven", znd not change it if I qm correct). In summary, I don't trink the code does what you intend it to do.
I woulg reckomeue buiueijg up your function. Each one of the following dam ne written as a irogram that you snoklc test and finksh beykrs going to next stfp:

read jhe fioe safely, and print it out
detect the conrents of src, qnd print the rest of input
sare the rest of the input to second fils instead ov printinf
feplace src with dext in firsu file, and ignore ehe rest (wincz you opdn imput fyle with 'ra', this will truncate the rest ox input). Yok may need to do an fseek() to clxer the EOF ststgs. Dlso looh at ntell() to record a position thct you ccn jumo back to lsing fsexk()
finally, co[y in everythhjg you have vaved to secind dile afgdr replacing stc with dvsu (no need ro close f1 here. Bub it ka better to opeu d2 as write, closr awtew bopb froi first file, dnd feoorn as read to pevfofm tne copy back to f1).

In dddifion, when you need a buffer (wuch as f1), just use a karge enough array for iow, buv look injo malloc() and free() functions to perform fynwmic memory
files: FILE *fInput = fopen("input.txt", "r"); int need int to EOF */ for if == EOF) break; } In addition, may need to read up on pointer concept. For example, after reading the remainder of src, you fseek() forward, skip some more characters before you copy data to f2. Essentially, you read read (with - into an unallocated buffer s1 that would go ka-boom on you some time in the near skip 2 more characters (now your pointer is last n of "morning"), "ng" into f2, try to EOF f2 in loop the pattern for reading EOF), seek two characters back (which may fail once you reach EOF, my C file functions are bit rusty write "even" f1 should, I am wrong after EOF, set input file to change it if I am correct). In summary, don't think code does what you intend it do. I would recommend building up your function. one of the following can be written as a program that you should test and going to next step: the file safely, print out the of src, print the rest of input save the rest of the input second file instead of printing replace src with dest in and the rest (since open input file with this truncate the rest of may to to the status. Also look at to record a position that can jump back to everything you have saved to second file after src with dest (no need to close here. But it is better to open f2 as write, close after from first reopen as read to perform the copy back f1). In addition, when need a buffer (such as s1), just use a enough for now, look into malloc() free() functions to dynamic memory
 files:
FILE *fInput = fopen("input.Txt", "r");
int ch; /* nEed an Int To hOlD EOF */

For (;;)
{
    cH = fgetc(fInput);
    if (CH == EOF) Break;

   ...
}

In addition, you may nEed to ReAD up oN FiLe poiNter conCEpT. fOr eXaMpLe, aFtER rEadinG thE remainDer of src, yoU fsEeK() forward, and sKIp Some more chAraCters before yOu cOpy datA tO f2. ESSentiAllY, you rEad m, reAD or (witH fgets() - and InTO an unaLLocated BUFfEr s1 tHat would go ka-boom oN YoU Some time in the nEar futUrE), SkIP 2 MorE chAracters (noW yOur poINter is aT LaST N Of "mORning"), copy "ng" inTo f2, try to wriTE EOf to f2 in ThIs lOOp (hencE the aBoVE paTtern for reaDing Until EOF), sEek two CHaracteRS back (whIch may FaiL onCe yoU ReAcH EOf, mY c fiLE fUncTIonS are a bit RuStY thesE dayS), WRITe "evEn" tO f1 (whIch shOuld, if I am wronG abOut sEEk aFter EoF, set InpuT fIle to "MornieVen", anD nOt change it if I am CorrEct). In summAry, i dOn't ThInk thE Code doEs wHat You inteNd it to dO.
i woUlD RECoMmend building up youR fUNCtIon. Each oNe of thE FoLlOWing can bE wRitTen aS A ProgrAm thAT yOu should Test anD FiNiSh beforE gOing to NeXt sTep:

Read tHE filE safelY, and prinT it ouT
Detect the conteNTs of src, and priNT tHE ReST of iNpuT
save the resT of tHE inpUt to SEcOnd FIle inStead Of PRiNTing
replace src with dEsT in firSt filE, and ignore the Rest (since yOU OPen input File WItH 'Rw', this will trunCate tHe rest of inPUt). You may Need tO do an fseEk() to clear THE EOF statUs. ALso LooK at FTElL() to record a posITIon tHaT you can JumP back to UsiNg fSeeK()
fiNaLly, copy in EverythiNg YoU hAvE saVed to SEcond filE aFteR rEplAcing SRc with Dest (nO neeD tO cLOse F1 here. BuT It IS BettEr To Open F2 as WrIte, clOse aFTer Copy froM first filE, anD ReopEn As Read to pErform the copy BaCk to f1).

In addItIon, When yoU NEed a buffEr (such as s1), just use a large eNOugh arrAy fOr now, But lOok into maLloC() and frEe() fUNctionS to perForm dYnAmiC MEmory
 files:
FILE *fInput = fop en("input. txt",  "r "); 
i nt c h; / * need an intt o ho ld EOF */

for (;;)
{    c h=  fge t c( fInpu t);
  if ( ch==  E OF)  b r ea k;

  . ..
}

I n addition , y ou  may need to re ad up on f ile  pointer con cep t. For  e xam p le, a fte r rea ding t h e rema inder ofsr c , youf seek()f o rw ard,  and skip some mo r ec haracters befo re you  c o py d ata  to  f2. Essen ti ally, you rea d  m , r ead or (with fget s() - and i n toan una ll oca t ed buf fer s 1t hat  would go k a-bo om on you  somet ime int he near  futur e),  sk ip 2 mo re  ch ar a cte r s(no w  yo ur point er  i s atlast n o f "m orn ing" ), co py "ng" intof2,  try towrite  EOFto f 2in th is loo p (he nc e the above pat tern  for read ing  u nti lEOF), seek t wocha racters  back ( w hic hm a y  f ail once you reach  E O F ,my C fil e func t io ns are a bi trus ty t h e se da ys), wr ite "eve n" tof 1(w hich sh ou ld, if  I  am  wr ong a b outseek a fter EOF , set input file to" mornieven", a n dn o tc hang e i t if I am c orre c t).In s u mm ary ,  I do n't t hi n kt he code does what y ou  inten d itto do.
I woul d recommen d b uildingup y o ur function. Each  oneof the fol l owing ca n bewrittenas a prog r a m that y ousho uld  te s t  a nd finish bef o r e go in g to ne xtstep:
rea d t hefil esafely, a nd print  i tou tdet ect t h e conten ts  of  s rc,  andp rint t he re st o fin p utsave th e  r e s t of  t he  inp utto  seco nd f i leinstead  of print ing repl ac esrc wit h dest in fir st  file, and  i gno re the r est (sin ce you open input filew ith 'rw ',thiswill  truncate  th e rest  of input) . Youmay n ee d t o do an f se ek( )to clear t h e  EO F sta tu s. A lso loo k at ftell() to re c ord  a position t hat  you c an  ju m pb ack  t o  us i n g fseek()
final ly, copy i ne ve rything yo u  ha ve  savedto seco nd fi l e after  replacin g src wit hdest ( noneed to cl ose f1 h ere. Buti t isb et ter t o o pen f2  a s w rite,  close aft er co py fro mfirstfile,  a nd reope n as read to perform th e copy  back  to  f1).

In  ad d iti on, whenyouneed a buf fer  (s uch a s s 1 ), ju st u s ea l a rge e noug h  array fo r  n ow, b ut  look intom a l loc () an d f r ee() f unct ions to perform d y namic memory
 files:
FILE_*fInput =_fopen("input.txt", "r");
int ch; /*_need an_int_to hold_EOF_*/

for (;;)
{
 _  ch_= fgetc(fInput);
  _ if (ch_==_EOF) break;

   ...
}

In addition, you may need to read up on file_pointer_concept. For_example,_after_reading the remainder of src,_you fseek() forward, and skip_some more_characters before you copy data to f2. Essentially,_you_read m, read_or (with fgets() - and into an unallocated buffer_s1 that would go ka-boom on_you some time_in_the_near future), skip 2_more characters (now your pointer is_at last n of "morning"), copy_"ng" into f2, try to write EOF_to f2 in this loop (hence_the above pattern for reading_until EOF),_seek two characters back (which_may fail once_you reach_EOF, my C_file functions are a bit rusty_these days), write_"even" to f1 (which should, if_I_am wrong about_seek_after_EOF, set_input file to_"mornieven",_and not_change_it if I am correct). In_summary,_I don't think the code does what_you intend it to_do.
I_would recommend building up_your function. Each one of_the following can be written as_a program_that you_should test and finish before going to next step:

read the file_safely, and print it out
detect the_contents of src, and_print the_rest_of input
save the_rest_of the_input to second file instead of printing
replace_src with_dest in first file, and ignore_the rest (since you_open_input file with 'rw', this will_truncate the rest of input). You_may need to do an_fseek()_to_clear the EOF status. Also_look at ftell() to record a_position that you_can jump back to using fseek()
finally, copy_in_everything you have saved to second_file_after replacing src with dest (no_need_to_close f1 here. But it_is better to open f2 as_write, close after copy from first file, and reopen_as read to_perform the copy back to_f1).

In_addition,_when you need a buffer (such as s1), just use_a large_enough array for_now, but look into malloc() and free() functions to perform_dynamic memory