Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* TAHMID RAHMAN
- DAMIAN FOREVER
- MATH LOVER
- NEVER GIVE UP
- */
- #include<stdio.h>
- #include<stdlib.h>
- int main(int argc, char *argv[])
- {
- FILE *from, *to;
- char ch;
- if(argc!=3)
- {
- printf("Usage: copy<source><destination>");
- exit(1);
- }
- if((from=fopen(argv[1], "rb"))==NULL)
- {
- printf("Can't open file.\n");
- exit(1);
- }
- if((to=fopen(argv[2], "wb"))==NULL)
- {
- printf("Can't open file.\n");
- exit(1);
- }
- while(!feof(from))
- {
- ch=fgetc(from);
- if(ferror(from))
- {
- printf("Error reading source file.\n");
- exit(1);
- }
- if(!feof(from))
- {
- fputc(ch, to);
- }
- if(ferror(to))
- {
- printf("Error writing destination file.\n");
- exit(1);
- }
- }
- if(fclose(from)==EOF)
- {
- printf("Error closing source file.\n");
- exit(1);
- }
- if(fclose(to)==EOF)
- {
- printf("Error closing destination file.\n");
- exit(1);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment