- #1
- 4,652
- 38
OK, so I've got this wacky homework assignment that involves reading stuff out of a .mp3 file. Just to get started, I am attempting to read the first four "bytes" of the file and put them into an (unsigned char) array. I am not really sure if I am reading from the file or not - I can't tell from these characters that I print out. Does this look right to you?
Here's the assignment I am working on by the way.
http://www.math.ucla.edu/~rclark/10a.1.05w/hw5/hw5.html
The teacher has written most of this for us and there's really just a few functions I have to write but I have been a nervous wreck trying to figure this out. I thought I better go ahead and post since I know I'll be working on it all weekend.
More questions coming soon.
Code:
# include <iostream>
# include <fstream>
using namespace std;
typedef unsigned char byte;
int main()
{
cout<< "enter the mp3 filename (including the .mp3): "<< endl;
char buff[100];
cin.getline(buff,100);
byte array[4];
ifstream in(buff, ios::in|ios::binary);
if(!in)
{
cout <<"no file found" << endl;
exit(1);
}
for (int i = 0; i<4;++i)
{
char ch;
in.get(ch);
array[i] = ch;
}
in.close();
for (int j = 0; j<4;++j)
cout << array[j];
cout <<endl;
return 0;
}
Here's the assignment I am working on by the way.
http://www.math.ucla.edu/~rclark/10a.1.05w/hw5/hw5.html
The teacher has written most of this for us and there's really just a few functions I have to write but I have been a nervous wreck trying to figure this out. I thought I better go ahead and post since I know I'll be working on it all weekend.
More questions coming soon.
Last edited by a moderator: