Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

simple binary read/write question

Posted on 2004-08-13
3
Medium Priority
?
255 Views
Last Modified: 2008-02-26
Hi everyone,

I have an mp3 file. I want to open it, then read in every byte into an array. Then using that storage array, I would like to write it back out to a new mp3 file.

Can I use c++'s ifstream class to simply get() a char at a time from the mp3 file, store it in a char array, then write it back out to the new file using put() for each element?

I am uncertain if this method will only work for a text document. If so, what can I use to accomplish this feat for a binary file, if an mp3 file indeed is one.

I am restrained to keeping the data alive in a buffer array and writing the copied file out in that manner.

Thanks for your time
0
Comment
Question by:ragin_cajun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
drichards earned 400 total points
ID: 11798061
You can do either binary file or text file that way.  You just have to open the file in binary mode.

Why wold you store the whole file in memory just to rewrite it out to a different file?  You could do it a few bytes at a time (chunks of a few K at a time or something) or just use a file copy command.
0
 
LVL 1

Author Comment

by:ragin_cajun
ID: 11798073
Thanks drichards, I know it is strange to do it this way.

I'm trying to teach myself winsock. I have a server and a client setup now, they can pass messages which is pretty fancy. I wanted to try passing a file. I thought on the server side I could load the file up into an array, then pass the bits of the array in messages to the client so it could reconstruct it on that side.

There must be a better way, I thought this might work just for kicks to start, thanks again!
0
 
LVL 19

Expert Comment

by:drichards
ID: 11798124
Over the network especially, you'll have to read in smaller chunks because you can't send huge packets over the network.  You'll probably want to keep it around 1K chunks.  Network MTU is usually 1500 bytes or less.  1K is pretty safe.  Even if you read the entire file into memory at once, you'll still have to break it into smaller size units for transmission.
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question