![]() |
| | #1 |
| Registered User Join Date: Oct 2009
Posts: 6
| I've got another question. Is there a function in C for copy? I saw this somewhere and wondering if there's one for 'copy': remove("Filename.txt"); // equivalent to 'delete filename.txt in dos rename("Fileold.txt", "Filenew.txt"); // equivalent to 'rename fileold.txt filenew.txt what about .. copy file1.txt file2.txt .. is there one for C? I tried copy, copyfile, filecopy all not working. Thanks, YetBo |
| YetBo is offline |
| | #2 |
| Jack of many languages Join Date: Nov 2007 Location: Katy, Texas
Posts: 1,931
| No Copy function. You'll have to read and write the file. Or, you could use the system() function and pass the copy command (which will then read and write the file for you).
__________________ Mac and Windows cross platform programmer. Ruby lover. Memorable Quotes From Recent Posts: I can't remember. |
| Dino is offline |
| | #3 |
| Registered User Join Date: Oct 2009
Posts: 6
| Hi Dino thanks for the quick reply. Mind showing me how the system() function works. And Happy Birthday !!! |
| YetBo is offline |
| | #4 |
| Jack of many languages Join Date: Nov 2007 Location: Katy, Texas
Posts: 1,931
| Thanks! system("copy a b") ;
__________________ Mac and Windows cross platform programmer. Ruby lover. Memorable Quotes From Recent Posts: I can't remember. |
| Dino is offline |
| | #5 |
| Super Moderator Join Date: Sep 2001
Posts: 4,680
| The string passed to system is executed as though it was entered at the command line. This makes it nice & easy for some things - but whatever you put in there is OS-dependant, and not really part of C, per se. Sometimes it's viewed as bad style. That being said, copy still works in Windows, on *nix you'd use the 'cp' command. |
| sean is offline |
| | #6 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Actually, switching out to the system copy command with system() is probably the most painless method. Copying a file is more than just creating a file with the same contents as some other file. You also need to preserve the creation date, file permissions, ownership, and any other attributes. Settings these attributes is a very non-portable operation, and in fact, it is impossible to implement a true file copy in C using only standard functions. So if you're going to delve into non-portability (and you must, if you need to copy files), you may as well reduce the pain to the minimum level possible by just calling system().
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline |
| | #7 | |
| Registered User Join Date: Nov 2008
Posts: 75
| Quote:
| |
| MisterIO is offline |
| | #8 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| What exactly do you think glib does internally? It calls platform-specific functions. There's nothing wrong with that, but it's incorrect to say that linking to some library which hides the non-portable details somehow makes your code portable. Your code still won't compile on any platform which isn't supported by glib. That's non-portable by definition. Non-portability is not a bad thing. The portable core of C and C++ is extremely restricted in what it can do. Real programs HAVE to go outside of those bounds.
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline |
| | #9 | |
| Registered User Join Date: Nov 2008
Posts: 75
| Quote:
| |
| MisterIO is offline |
| | #10 | |
| Super Moderator Join Date: Sep 2001
Posts: 4,680
| Quote:
brewbuck - good point, I agree - I was sharing that more as an intro to the "system" function in general though. I think it's grossly overused by people who have recently discovered it. | |
| sean is offline |
| | #11 | |
| Registered User Join Date: Nov 2008
Posts: 75
| Quote:
What exactly do you think "the c standard library" does internally? It calls platform-specific functions. | |
| MisterIO is offline |
| | #12 | |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Quote:
glib is not a standard, is not required to be present on a system, is not required to be operable on any possible system.
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot | |
| brewbuck is offline |
| | #13 | |
| Registered User Join Date: Nov 2008
Posts: 75
| Quote:
| |
| MisterIO is offline |
| | #14 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| If your code adheres to all standard C rules, then your code is portable to any environment with a standard C compiler. If you're claiming otherwise, I'd like to hear your argument.
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline |
| | #15 |
| Registered User Join Date: Nov 2008
Posts: 75
| Again, this is completely irrelevant to the previous discussion and I never said that. It just seems to me that you're unable to admit that you were wrong. |
| MisterIO is offline |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Creepy DOS and BIOS functions (need help!!!) | James00 | C Programming | 9 | 05-05-2003 12:40 AM |
| how many old school DOS programmers are left? | Waldo2k2 | A Brief History of Cprogramming.com | 23 | 02-01-2003 05:14 PM |
| File systems?? (Winxp -> DOS) | Shadow | Tech Board | 4 | 01-06-2003 09:08 PM |
| Quick ? on copy constructor | Traveller | C++ Programming | 3 | 05-03-2002 10:31 AM |
| Copy Constructor Help | Jubba | C++ Programming | 2 | 11-07-2001 11:15 AM |