The program takes command line arguments for source and destination file.
#include<stdio.h>
void main(int argc,char *argv[])
{
if(argc!=3)
{
printf("Very few arguments to operate on");
return;
}
FILE *sp,*dp;
char c;
sp=fopen(argv[1],"r");
if(sp==NULL)
{
printf("%s cannot be opened in read only mode. make sure the file exists",argv[1]);
return;
}
dp=fopen(argv[2],"w+");
if(dp==NULL)
{
printf("%s cannot be created",argv[2]);
return;
}
while(!feof(sp))
{
c=fgetc(sp);
fputc(c,dp);
}
fclose(sp);
fseek( dp, 0, SEEK_SET );
while(!feof(dp)){
c=fgetc(dp);
printf("%c",c);
}
fclose(dp);
}
but if the source file has "Hi! I an Anudeep" then after copying the file has "Hi! I an Anudeepÿ". Help me fix this.