Header Ads

test

FILE COPY PROGRAM IN C SOURCE CODE

/* WARNING: be sure to edit the line 23 and make "text the file you
want to copy, be sure to leave the file name in quotes, filename can me
relative or absolute
*/
#include <stdio.h>
int main()
{
		 char c[100];
		 FILE *inFile;
		 FILE *outFile;
		 char sourceFile;
		 char destFile;
		 int Byte;
		 int i;
//		 printf("Enter the File Name to read: ");
//		 scanf("%s",&sourceFile);
		 printf("Enter the File Name to write to: ");
		 scanf("%s",&destFile);
		 inFile = fopen("text", "rb");
		 /*open a text file for reading in binary */
		 outFile = fopen(&destFile, "wb");
		 /*open a text file for writing in binary*/
		 if(inFile==NULL)
		 {
		 /*if pointer to inFile is a null pointer,
		   return an error and display msg */
		 		 printf("Error: Can't Open sourceFile
");
		 		 /*be sure not invoke fclose, because
		 		   you can't pass a NULL pointer to it
		 		 */
		 		 return 1; //return 1 for error;
		 }
		 if(outFile==NULL)
		 {
		 		 printf("Error: Can't Open DestFile
");
		 		 return 1;
		 }
		 else
		 {
		 		 printf("File Opened Successfully.");
		 		 printf("
Contents:
");
		 		 while(1)
		 		 {
		 		 		 if(Byte!=EOF)
		 		 		 {
		 		 		 Byte=fgetc(inFile);
		 		 		 printf("%d",Byte);
		 		 		 fputc(Byte,outFile);
		 		 		 }
		 		 		 else
		 		 		 {
		 		 		 break;
		 		 		 }
		 		 }
		 /*		 for(i=0;c!='
			

No comments

please write your mail id for contact: