EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies /  /*simple program of file

 /*simple program of file

|

Miscellaneous › Others › Programs related to file handling in C language. ›  /*simple program of file

March 25, 2013 at 7:01 am #9370
Arjun Vaghani
Participant

 

/*simple program of file Handling*/
/*copy content of 1 file to another*/
 
#include<stdio.h>
main(int argc, char **argv)
{
 char ch;
 FILE *fp1,*fp2;
 
 if(argc!=3)
 {
   printf(“Invalid syntax: use: ./cpy <source_filename> <destinatin_filename>n”);
   return;
 }
 
 fp1=fopen(argv[1],”r”); 
 if(fp1==NULL)
 {
 printf(“source file does not existsn”);
 return;
 }
fclose(fp1);
 
 fp2=fopen(argv[2],”r”);
 if(fp2!=NULL)
 {
here: printf(“Ur file already exists..Do u want to overwrite? press y for yes and n for no:”);
      scanf(“%c”,&ch);
 
      if(ch==’n’||ch==’N’)
         return;
      else if(ch!=’y’&& ch!=’Y’)
      {
         printf(“Invalid choicen”);
         goto here;
      }
  fclose(fp2);
  while((ch=getchar())!=’n’); /*for clearing buffer*/
 }
 
 fp1=fopen(argv[1],”r”);
 fp2=fopen(argv[2],”w”);
 
 while((ch=fgetc(fp1))!=EOF)
 {
  fputc(ch,fp2);
 }
 fclose(fp1);
 fclose(fp2);
}
 

 

RSS Recent Posts

  • Convenient audio FFT module? February 16, 2026
  • RC Electronic Speed Control Capacitors February 16, 2026
  • CR2/CR123A Batteries In Projects February 16, 2026
  • Harman Kardon radio module BMW noise February 16, 2026
  • analog logic of shmidt trigger bjt circuit February 16, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise