Copying a microsoft word doc

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: Copying a microsoft word doc

 
0
  #11
Jul 2nd, 2009
Hey AD, in your post (#3) you forgot an ending bracket on this line:
while( fin.read( iobuffer, sizeof(iobuffer) )
Last edited by tux4life; Jul 2nd, 2009 at 7:36 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,408
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1469
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Copying a microsoft word doc

 
0
  #12
Jul 2nd, 2009
Originally Posted by tux4life View Post
Hey AD, in your post (#3) you forgot a bracket on this line:
while( fin.read( iobuffer, sizeof(iobuffer) )
Nobody is perfect
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 14
Reputation: shealy is an unknown quantity at this point 
Solved Threads: 0
shealy shealy is offline Offline
Newbie Poster

Re: Copying a microsoft word doc

 
0
  #13
Jul 3rd, 2009
II have written code that can successfully read and write a microsoft word doc - that is if the word doc contains plain text only. If there are any headings and different fonts used, these are not copied successfully. Which brings me back to my original question - when copying word docs does one need to manipulate the non-ascii chars? And how is this done?





Originally Posted by Ancient Dragon View Post
When I actually tried it I had the same problem. I used a command prompt and found out that the two files were just a few bytes different.

well, the code I posted almost works. The problem is that the last few bytes does not get read/written
  1. int main(int argc, char* argv[])
  2. {
  3. char iobuf[255];
  4. size_t total = 0;
  5. size_t sz = 0;
  6. ifstream fin("file1.doc", ios::binary);
  7. if( !fin.is_open() )
  8. {
  9. cout << "Can't open the file\n";
  10. return 1;
  11. }
  12. ofstream fout( "copy.doc", ios::binary);
  13. while( fin.read(iobuf, sizeof(iobuf) ))
  14. {
  15. sz = fin.gcount();
  16. total += sz;
  17. fout.write(iobuf, sz);
  18. sz = 0;
  19. }
  20. sz = fin.gcount();
  21. if( sz > 0)
  22. {
  23. cout << "sz = " << sz << "\n";
  24. total += sz;
  25. fout.write(iobuf, sz);
  26. }
  27. fin.close();
  28. fout.close();
  29. cout << "Total = " << total << "\n";
  30. return 0;
  31. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,408
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1469
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Copying a microsoft word doc

 
0
  #14
Jul 3rd, 2009
Originally Posted by shealy View Post
II have written code that can successfully read and write a microsoft word doc - that is if the word doc contains plain text only
That isn't a microsoft word doc, but a normal text file.

Originally Posted by shealy View Post
. If there are any headings and different fonts used, these are not copied successfully. Which brings me back to my original question - when copying word docs does one need to manipulate the non-ascii chars? And how is this done?
See the code I already posted and which you quoted. If all you want to do is copy the file then the answer to your question is NO.
Last edited by Ancient Dragon; Jul 3rd, 2009 at 11:55 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 14
Reputation: shealy is an unknown quantity at this point 
Solved Threads: 0
shealy shealy is offline Offline
Newbie Poster

Re: Copying a microsoft word doc

 
0
  #15
Jul 6th, 2009
The microsoft word doc is copied successfully - byte per byte. Copied file is same size as original. However, when I try and use microsoft word to open the copied file, the copied file contents which have non-ascii text are not readable. The ascii text is readable. So the copied file is worthless to the end user if he/she cannot see the non-ascii parts. So I want to be able to copy the file AND open it and read it successfully using ms-word.


Originally Posted by Ancient Dragon View Post
That isn't a microsoft word doc, but a normal text file.



See the code I already posted and which you quoted. If all you want to do is copy the file then the answer to your question is NO.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,408
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1469
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Copying a microsoft word doc

 
0
  #16
Jul 6th, 2009
Originally Posted by shealy View Post
The microsoft word doc is copied successfully - byte per byte. Copied file is same size as original. However, when I try and use microsoft word to open the copied file, the copied file contents which have non-ascii text are not readable. The ascii text is readable. So the copied file is worthless to the end user if he/she cannot see the non-ascii parts. So I want to be able to copy the file AND open it and read it successfully using ms-word.
Zip up the file you are trying to copy and post it so that I can test it. The doc file I tested is readable by MS-Word as expected, and it contains quite a bit of graphics and charts, so there is no reason that program does not work with any document.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: Copying a microsoft word doc

 
0
  #17
Jul 6th, 2009
I can confirm AD's code works correctly.
(Also tested it on a couple of Word files, playing a bit with the formatting)
The file is loading correctly after copying.

To the OP:
Ensure that you're copying a file which isn't corrupted, before copying you should check whether the file you want to copy loads correctly in MS Word, otherwise you've already missed the boat before the copying process starts.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 14
Reputation: shealy is an unknown quantity at this point 
Solved Threads: 0
shealy shealy is offline Offline
Newbie Poster

Re: Copying a microsoft word doc

 
0
  #18
Jul 6th, 2009
Attached is the input file - Input.doc and the output file that is created - Output.doc. As you can see outfile looks very different to the inputfile. I used the code that you provided to test this.


Originally Posted by Ancient Dragon View Post
When I actually tried it I had the same problem. I used a command prompt and found out that the two files were just a few bytes different.

well, the code I posted almost works. The problem is that the last few bytes does not get read/written
  1. int main(int argc, char* argv[])
  2. {
  3. char iobuf[255];
  4. size_t total = 0;
  5. size_t sz = 0;
  6. ifstream fin("file1.doc", ios::binary);
  7. if( !fin.is_open() )
  8. {
  9. cout << "Can't open the file\n";
  10. return 1;
  11. }
  12. ofstream fout( "copy.doc", ios::binary);
  13. while( fin.read(iobuf, sizeof(iobuf) ))
  14. {
  15. sz = fin.gcount();
  16. total += sz;
  17. fout.write(iobuf, sz);
  18. sz = 0;
  19. }
  20. sz = fin.gcount();
  21. if( sz > 0)
  22. {
  23. cout << "sz = " << sz << "\n";
  24. total += sz;
  25. fout.write(iobuf, sz);
  26. }
  27. fin.close();
  28. fout.close();
  29. cout << "Total = " << total << "\n";
  30. return 0;
  31. }
Attached Files
File Type: doc Input.doc (12.2 KB, 3 views)
File Type: doc Output.doc (12.2 KB, 3 views)
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 14
Reputation: shealy is an unknown quantity at this point 
Solved Threads: 0
shealy shealy is offline Offline
Newbie Poster

Re: Copying a microsoft word doc

 
0
  #19
Jul 6th, 2009
File is def not corrupted before copying. FYI am using a C++ binary on 2.8 sun solaris operating system. Run the binary and binary creates Output.doc from Input.doc. Output.doc is then ftp'd to desktop where I use miscrosoft word to open it.

Thanks for the help so far.


Originally Posted by tux4life View Post
I can confirm AD's code works correctly.
(Also tested it on a couple of Word files, playing a bit with the formatting)
The file is loading correctly after copying.

To the OP:
Ensure that you're copying a file which isn't corrupted, before copying you should check whether the file you want to copy loads correctly in MS Word, otherwise you've already missed the boat before the copying process starts.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,408
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1469
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Copying a microsoft word doc

 
0
  #20
Jul 6th, 2009
There might be ftp problem. And I don't know what will happen if you try to copy MS-World doc file on your solaris operating system.
Last edited by Ancient Dragon; Jul 6th, 2009 at 9:23 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC