| | |
can't copy existing file into new file
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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....?
but it can't do so throught the command line arg. what is
the solution....?
c Syntax (Toggle Plain Text)
#include<stdio.h> #include<conio.h> #include<stdlib.h> void main(char *argv[]) { FILE *fp1,*fp2; char c; int i; clrscr(); fp1=fopen(argv[1],"r"); rewind(fp1); fp2=fopen(argv[2],"w"); if(fp1==NULL) { printf("Source File is Not Exist"); exit(0); } while((c=getc(fp1))!=EOF) { putc(c,fp2); printf("%c",c); } fclose(fp1); fclose(fp2); getch(); }
Last edited by Ancient Dragon; Jan 5th, 2009 at 9:39 pm. Reason: add code tags
1. Wrong main prototype. Must be:
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.
c Syntax (Toggle Plain Text)
int main(int argc, char*argv[])
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.
•
•
•
•
1. Wrong main prototype. Must be:
2. fgetc returns int, declare c as int.c Syntax (Toggle Plain Text)
int main(int argc, char*argv[])
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.
>>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.
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.
![]() |
Similar Threads
- System32/Config/ System missing on XP PRO and Home dual boot system (Windows NT / 2000 / XP)
- writing to a file (C++)
- printing text file string contents (array) - padded characters (C++)
- How to rename existing (running) jar file? (Java)
- POS.tmp file and red X problem (Viruses, Spyware and other Nasties)
- How to write the new line existing pdf file using php (PHP)
- File Processing C++ (C++)
- copying a file in python (Python)
- himem.sys file causing windows not to load (Windows 95 / 98 / Me)
Other Threads in the C Forum
- Previous Thread: Unable to open file with fopen
- Next Thread: Append a Character(backslash) to a string at any position
Views: 828 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C
#include * ansi array arrays asterisks binarysearch calculate changingto char cm command convert copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv fflush file fork forloop framework functions getlasterror givemetehcodez grade graphics gtkwinlinux hacking hardware histogram homework inches include incrementoperators input iso kernel keyboard km lazy linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft motherboard mqqueue number opendocumentformat opensource overwrite owf pattern pdf performance pointer posix problem probleminc process program programming radix recursion recv research reversing scanf scripting segmentationfault sequential socket socketprograming spoonfeeding standard string structures student systemcall testing threads turboc unix user variable voidmain() wab whythiscodecausesegmentationfault windowsapi






