I'm writing this program to read in bitmap files (in Linux). It's not finished, but it does seem to read in the header info correctly so it'll be easy enough to do the rest. I'm just worried that I'm making this harder than it needs to be. Is there an easier or more elegant way to go about this?

What about this code, stylewise & so on -- my C++ is pretty rusty & it was never very brilliant to begin with -- any suggestions on aspects that need improvement?

Finally: at the end of main() I print out the bytes one at a time to check the data that I saved in Header. When I run it on the file TEST.bmp here:
http://www.geocities.com/velocide/index.html
the third byte is printing as ffffffc6 instead of just c6. I guess thats because of the leading 1 in the binary 11010110, but there must be a way to print it as just "c6". How?

Thanks for looking.

Here's the code:
Code:
#include <iostream>
#include <fstream>
#include "Header.h"

using namespace std;

int main(int argc, char* argv[]) {
	ifstream infile(argv[1], ios::in|ios::binary);
	Header *myHeader = new Header();
	char c;
	char *pc = &c;
	unsigned short s = 0;
	char *ps = (char*)&s;
	unsigned long l = 0;
	char *pl = (char*)&l;
	if(infile.is_open()) {
		infile.read(pc,1);
		myHeader->setSig1(c);
		infile.read(pc,1);
		myHeader->setSig2(c);
		infile.read(pl, 4);
		myHeader->setFileSize(l);
		infile.read(ps, 2);
		if(s) {
			cout << "Invalid data: filler1 = " << s << endl;
			return 0;
		}
		infile.read(ps, 2);
		if(s) {
			cout << "Invalid data: filler2 = " << s << endl;
			return 0;
		}
		infile.read(pl, 4);
		myHeader->setPixDatOffset(l);
		infile.read(pl, 4);
		if(l != 40) {
			cout << "Invalid data: headerSize = " << l << endl;
			return 0;
		}

//		infile.close();
	}else {
		cout << "readBinFile: Unable to open file " << argv[1] << endl;
		return 0;
	}
	
	cout << "Finished reading header." << endl;
	cout << "File signature: " << myHeader->getSig1() << myHeader->getSig2() << endl;
	cout << "File size: " << myHeader->getFileSize() << endl;
	cout << "Pixel data offset: " << myHeader->getPixDatOffset() << endl;

	infile.seekg(0);
	cout << endl;
	cout << "First 18 bytes of file " << argv[1] << ":" << endl;
	for (int i=0; i<18; i++) {
		infile.read(pc, 1);
		cout << hex << (unsigned int)c << endl;
	}
	return 0;
}
Code:
class Header
{
public:
	Header() {
		filler1 = 0;
		filler2 = 0;
		headerSize = 40;
	}
	virtual ~Header(){}

	void setSig1(char& c) {sig1 = c;}
	void setSig2(char& c) {sig2 = c;}
	void setFileSize(unsigned long s) {fileSize = s;}
	void setPixDatOffset(unsigned long s) {pixDatOffset = s;}
	char getSig1() {return sig1;}
	char getSig2() {return sig2;}
	unsigned long getFileSize() {return fileSize;}
	unsigned long getPixDatOffset() {return pixDatOffset;}


private:
	char sig1;
	char sig2;
	unsigned long fileSize;
	unsigned short filler1;
	unsigned short filler2;
	unsigned long pixDatOffset;
	unsigned long headerSize;

};
and the test output:
Code:
Finished reading header.
File signature: BM
File size: 1478
Pixel data offset: 1078

First 18 bytes of file TEST.bmp:
42
4d
ffffffc6
5
0
0
0
0
0
0
36
4
0
0
28
0
0
0