/* Jason Dirner and Nelson Li EE 476 Spring 2002 Final Project */ // Program to convert an MP3 file to an array of characters #include #include using namespace std; int main(int argc, char* argv[]) { // Local variables char mp3_char; char mp3_hex_char[20]; int hex_count = 0; // Quit if no MP3 file is given if (argc < 2) exit(1); // Open the MP3 ifstream mp3_file; mp3_file.open(argv[1]); if(mp3_file.fail()) { cout << "Error: Could not open MP3.\n"; exit(1); } // Open the output file ofstream mp3_hex; mp3_hex.open("MP3_hex.out"); if(mp3_hex.fail()) { cout << "Error: Could not open output file.\n"; exit(1); } // Begin the array mp3_hex << "{"; // Output the MP3 in hex format to the output file while (!mp3_file.eof()) { mp3_file.get(mp3_char); if (mp3_file.eof()) sprintf(mp3_hex_char, "0x%02hhx}", mp3_char); else sprintf(mp3_hex_char, "0x%02hhx, ", mp3_char); mp3_hex << mp3_hex_char; if (hex_count >= 19) { mp3_hex << endl; hex_count = 0; } else hex_count++; } // Close the input/output streams mp3_file.close(); mp3_hex.close(); return 0; }