can't copy existing file into new file

Reply

Join Date: Jan 2009
Posts: 25
Reputation: nitu_thakkar has a little shameless behaviour in the past 
Solved Threads: 1
nitu_thakkar's Avatar
nitu_thakkar nitu_thakkar is offline Offline
Light Poster

can't copy existing file into new file

 
-1
  #1
Jan 5th, 2009
this coding is about copy one existing file into other file

but it can't do so throught the command line arg. what is

the solution....?
  1. #include<stdio.h>
  2.  
  3. #include<conio.h>
  4.  
  5. #include<stdlib.h>
  6.  
  7. void main(char *argv[])
  8. {
  9.  
  10. FILE *fp1,*fp2;
  11. char c;
  12. int i;
  13.  
  14. clrscr();
  15.  
  16. fp1=fopen(argv[1],"r");
  17.  
  18. rewind(fp1);
  19.  
  20. fp2=fopen(argv[2],"w");
  21.  
  22.  
  23. if(fp1==NULL)
  24. {
  25.  
  26. printf("Source File is Not Exist");
  27. exit(0);
  28.  
  29. }
  30.  
  31.  
  32.  
  33. while((c=getc(fp1))!=EOF)
  34. {
  35.  
  36.  
  37. putc(c,fp2);
  38.  
  39. printf("%c",c);
  40.  
  41.  
  42. }
  43.  
  44. fclose(fp1);
  45.  
  46. fclose(fp2);
  47.  
  48. getch();
  49.  
  50. }
Last edited by Ancient Dragon; Jan 5th, 2009 at 9:39 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: can't copy existing file into new file

 
0
  #2
Jan 5th, 2009
1. Wrong main prototype. Must be:
  1. int main(int argc, char*argv[])
2. fgetc returns int, declare c as int.
3. No need in rewind(fp1). Test fp1 == 0 befory any ops with opened file.
4. Test argc == 3 (argv[0] - program name, argv[1] and argv[2] - file names).
5. You can't copy binary file in text mode. To open in binary mode use "rb" and "wb" open mode arguments.
Last edited by ArkM; Jan 5th, 2009 at 7:01 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 25
Reputation: nitu_thakkar has a little shameless behaviour in the past 
Solved Threads: 1
nitu_thakkar's Avatar
nitu_thakkar nitu_thakkar is offline Offline
Light Poster

Re: can't copy existing file into new file

 
0
  #3
Jan 6th, 2009
Originally Posted by ArkM View Post
1. Wrong main prototype. Must be:
  1. int main(int argc, char*argv[])
2. fgetc returns int, declare c as int.
3. No need in rewind(fp1). Test fp1 == 0 befory any ops with opened file.
4. Test argc == 3 (argv[0] - program name, argv[1] and argv[2] - file names).
5. You can't copy binary file in text mode. To open in binary mode use "rb" and "wb" open mode arguments.

i have tried it but there is no change i got the same massage

here, getc() function used for get the value from existing file ,

character by character & put into new file

( which is given during run time )

character by character

can u pls send me more detail....?
Last edited by nitu_thakkar; Jan 6th, 2009 at 1:28 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,356
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: can't copy existing file into new file

 
0
  #4
Jan 6th, 2009
>>i have tried it but there is no change i got the same massage
What error message -- you never said what that was. Post code and make sure main() is declared like ArkM posted.

Post code if you need more help. And if you are trying to copy binary files then you have to open the files in binary mode, also as previously suggested.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC