Arduino Projects   |   Raspberry Pi   |   Electronic Circuits   |   AVR   |   PIC   |   8051   |   Electronic Projects

Programs related to file handling in C language.

2 posts / 0 new
Last post
Monika
Monika's picture
Offline
Last seen: 1 year 5 months ago
Joined: 21/02/2013 - 10:38
Programs related to file handling in C language.

Hi!!

     Its great to be a part of this team. I just went through the C programs disscussed over here and found them quite worthy. Can I please get some programs related to file handling in C.

 

 

Arjun Vaghani
Arjun Vaghani's picture
Offline
Last seen: 2 years 4 months ago
Joined: 24/03/2013 - 10:33
 /*simple program of file

 

/*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 exists\n");
 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 choice\n");
         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);
}
 

 

Log in or register to post comments

APPLICATIONS & TECHNOLOGIES

Learn about the latest applications and industry trends with tutorials and white paper design resources on vertical markets.

Automotive
Energy Harvesting
MEMS Technology
OpenSource Hardware
RFID & NFC
RF Wireless
Sensor
Solar
Touch
Wireless Charging