123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

   Computer Science / IT
   Electronics
   Electrical
   Mechanical
   Chemical
   Civil

   CAT / MBA

   GMAT / Foreign MBA
Latest Jobs

Engineering Jobs / Technical Jobs
Management Jobs

Sitemap
Terms of use

Displaying  Source Code(s)  
 

 
File Copy Program in C

--------------------------------------------------------------------------------

Description : A simple program that demonstrates File I/O, arrays, and pointers.

/* 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<BR>);
/*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<BR>);
return 1;
}
else
{
printf("File Opened Successfully.");
printf("
Contents:<BR>);

while(1)
{
if(Byte!=EOF)
{
Byte=fgetc(inFile);
printf("%d",Byte);
fputc(Byte,outFile);
}
else
{
break;
}
}
/* for(i=0;c!='
 

 

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved copyright 123ENG