C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 11th, 2006, 02:31 PM
BoAl BoAl is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 2 BoAl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 55 sec
Reputation Power: 0
How to copy!

I hope i am posting this in the right place .Anyway my question is :How can you copy a file ,an "something.exe "usin only borlandc 3.1?
It is very important to me ,please help!

Reply With Quote
  #2  
Old January 11th, 2006, 04:46 PM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 1,001 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3
Time spent in forums: 6 Days 15 h 6 m 59 sec
Reputation Power: 6
Send a message via ICQ to Itsacon
two possibilities:
  • Use the system() function, which allows you to execute a system call, like copy.
  • Open the file using fopen(), open the target file with fopen(), read everything from the source file, and write to the other file.

Something like this:
C Code:
Original - C Code
  1. #include <stdio.h>
  2.  
  3. int copy(const char* srcname, const char* dstname)
  4. {
  5.     /*  declare file pointers, and buffer char    */
  6.     FILE *src, *dst;
  7.     char buff;
  8.  
  9.     /*  open files    */
  10.     if(!(src = fopen(srcname, "rb")))      /* open for read, binary    */
  11.         return -1;
  12.  
  13.     if(!(dst = fopen(dstname, "wb")))      /* open for write, binary   */
  14.     {
  15.         fclose(src);
  16.         return -1;
  17.     }
  18.  
  19.     /*  read byte from src, and write to destination    */
  20.     while(fread(&buff, sizeof(char), 1, src))
  21.         if(!fwrite(&buff, sizeof(char), 1, dst))
  22.         {
  23.             fclose(src);
  24.             fclose(dst);
  25.             return -1;
  26.         }
  27.  
  28.     /*  return succes */
  29.     return 0;
  30. }
  31.  
  32. int main(int argc, char **argv)
  33. {
  34.     /*  check if all parameters are there */
  35.     if(argc < 3)
  36.     {
  37.         printf("Not enough paramters.\n Correct usage: %s <source> <destination>\n", argv[0]);
  38.         return -1;
  39.     }
  40.  
  41.     /*  copy files    */
  42.     if(copy(argv[1], argv[2]))
  43.     {
  44.         printf("Copying failed");
  45.         return -1;
  46.     }
  47.  
  48.     /*  return succes */
  49.     return 0;
  50. }


Just the copy() function, the main() is just to show how it works.
__________________
This is my code. Is it not nifty?

"The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools."
---Douglas Adams


Join the Itsacon fanclub!    
Zero Tolerance: Spammers banned so far: 280

Reply With Quote
  #3  
Old January 12th, 2006, 02:59 PM
BoAl BoAl is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 2 BoAl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 55 sec
Reputation Power: 0
It worked,Thx ,thogh i have another request, how can i make it run it's self if it is an .exe after it and can i make it copy itself,and can i make it copy itself in each folder in his folder and how?

Reply With Quote
  #4  
Old January 12th, 2006, 08:56 PM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 1,001 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3Folding Points: 1003874 Folding Title: Super Ultimate Folder - Level 3
Time spent in forums: 6 Days 15 h 6 m 59 sec
Reputation Power: 6
Send a message via ICQ to Itsacon
I'll see if I can answer that when I'm sober.. (damn...good party!)...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > How to copy!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT