|
![]() |
|
| Author |
|
|||||||
|
thre3dee
Posts: 996
Location: Brisbane, Queensland
|
i've decided to learn a bit of C++ while im doin uni and i'm trying to copy an existing file. int main() { FILE *oldFile; FILE *newFile; char fileOp; oldFile = fopen ("test.bmp","rb"); newFile = fopen ("testcopy.bmp", "wb"); if (oldFile==NULL) { printf("Error opening file"); } else{ (this is where i'll put the copying code) } system("pause"); return 0; } anyone know how to use fputc and fgetc to read each byte of 'oldFile' into the variable 'fileOp' and write them out to the file 'newFile'. my friend showed me how to do it but the .cpp file's on some other comp at uni and he's not available atm. |
|||||||
| #0 03:07pm 22/02/05 |
|
|||||||
|
system
|
--
|
|||||||
| #0 |
|
|||||||
|
Opec
Posts: 2814
Location: Brisbane, Queensland
|
Is this for Windows C++ or Unix C++?
|
|||||||
| #1 02:57pm 22/02/05 |
|
|||||||
|
thre3dee
Posts: 997
Location: Brisbane, Queensland
|
windows
i'm using visual c++ .NET if thats any help last edited by thre3dee at 15:02:40 22/Feb/05 |
|||||||
| #2 03:02pm 22/02/05 |
|
|||||||
|
Opec
Posts: 2815
Location: Brisbane, Queensland
|
Try this:
last edited by Opec at 15:26:51 22/Feb/05 |
|||||||
| #3 03:26pm 22/02/05 |
|
|||||||
|
thre3dee
Posts: 998
Location: Brisbane, Queensland
|
didnt work
the file is created but the data isnt copied (just a new bitmap with some black lines in it) |
|||||||
| #4 03:26pm 22/02/05 |
|
|||||||
|
Opec
Posts: 2816
Location: Brisbane, Queensland
|
heh it worked on my Unix box... of course it wouldn't work in Windows.
|
|||||||
| #5 03:27pm 22/02/05 |
|
|||||||
|
thre3dee
Posts: 999
Location: Brisbane, Queensland
|
do u know the windows code then?
excuse the newbieness to c++ |
|||||||
| #6 03:29pm 22/02/05 |
|
|||||||
|
rodolphe
Posts: 99
Location: Brisbane, Queensland
|
I was going through some old texts today and am selling them all... I have 4 programming texts, very basic ones. If Opec dun help you, you can buy the books from me :D
|
|||||||
| #7 03:39pm 22/02/05 |
|
|||||||
|
Strik3r
Posts: 1088
Location: Gold Coast, Queensland
|
Avoid using the FILE structure.. if your at uni you will be taught fstream's Using as much of your code as possible, heres something that should work.
I havent tested, but i think it should work. also, learn to lineup your braces properly, or people will think your a java noob :D excuse the lack of tabs i dont know how to make them work in forums.. if u cant read it very good, ill put it on rafb.net last edited by Strik3r at 15:46:14 22/Feb/05 |
|||||||
| #8 03:46pm 22/02/05 |
|
|||||||
|
Raven
Posts: 817
Location: Melbourne, Victoria
|
It might be worth pointing out that everything you've put in the initial post is straight C, not C++.
|
|||||||
| #9 03:59pm 22/02/05 |
|
|||||||
|
thre3dee
Posts: 1000
Location: Brisbane, Queensland
|
thx if it doesnt work then i'll go through the errors and try and fix em.
i'm used to higher level stuff like actionscript and stuff so yeah |
|||||||
| #10 04:09pm 22/02/05 |
|
|||||||
|
stinky
Posts: 492
Location: Brisbane, Queensland
|
WTF striker? that's not lining up your braces properly, indent them for nested braces. damn Java n00b!
|
|||||||
| #11 05:23pm 22/02/05 |
|
|||||||
|
habib
Posts: 336
Location: Brisbane, Queensland
|
erm....
how about
or, if you insist on doing it the way you described:
pretty sure that will work. |
|||||||
| #12 08:51pm 22/02/05 |
|
|||||||
|
Strik3r
Posts: 1089
Location: Gold Coast, Queensland
|
WTF striker? that's not lining up your braces properly, indent them for nested braces. damn Java n00b! ...... it wouldnt be because the forum didnt like the tab charecters i copied straight from my compiler would it..... nitwit last edited by Strik3r at 23:33:13 22/Feb/05 |
|||||||
| #13 11:33pm 22/02/05 |
|
|||||||
|
system
|
--
|
|||||||
| #13 |
|
|||||||
|
| ||||||||