Thread: HexDump Programm....

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    14

    HexDump Programm....

    Hello every one.... can you help me out here...
    I need to make 2 programms.. on C and other same C++

    I need to make a programms that read binary file (like txt file) and produce a hexadecimal dump of that file.

    output should look like this (out put should be stored in new txt file)

    http://img239.imageshack.us/img239/9...titled1ua6.jpg

    Also command line should be used to get the name of data file. and then program will use a lookup table to convert the binary byte to a hex character. Using printf is disallowed.

    Here is C programm.... but I have few problems..
    First.. how do I open file in C, using console entry?... (I got this workng in C++ but not in C)
    This programm just drive me nuts...

    Code:
    #include <stdio.h>
    int main(int argc,char* argv[])
    {
    	FILE* fileHandle;
    	if (argc != 2)
    	{
    		printf("Usage: hexdump <file name>\n");
    		return -1;
    	}
    	fileHandle = fopen(argv[1], "rb");
    	if (!fileHandle)
    	{
    		printf("Error: failed to open file %s for read", argv[1]);
    		return -1;
    	}
    	/* dump data here */
    	fclose(fileHandle);
    	return 0;
    }
    unsigned char lower(unsigned char c)
    {
    	unsigned char one_byte;
    	one_byte = c & 0x0F;
    	return one_byte;
    }
    unsigned char upper(unsigned char c)
    {
    	unsigned char one_byte;
    	one_byte = (c & 0xF0) >> 4;
    	return one_byte;
    }

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    14
    is there any C++ exemples?

    In C++ I was able to open file.. and write some to it.. but.. how do I change it to hex?

    Here what I did in C++

    int main()
    {

    string fileName;
    ifstream inData;
    ofstream outData;
    cout << "Enter the input file name: ";
    cin >> fileName;
    inData.open(fileName.c_str());
    outData.open("name1.txt");
    }
    That file enty part...


    Here is how I can write some thing using original file content.. and change it and write it to new file...
    string socialNum;
    string firstName;
    string lastName;
    string middleName;
    string initial;



    inData >> socialNum >> firstName >> middleName >> lastName;

    initial = middleName.substr(0, 1) + '.';


    outData << firstName << ' ' << middleName << ' ' << lastName
    << ' ' << socialNum << endl;
    outData << lastName << ", " << firstName << ' ' << middleName
    << ' ' << socialNum << endl;
    outData << lastName << ", " << firstName << ' ' << initial
    << ' ' << socialNum << endl;
    outData << firstName << ' ' << initial << ' ' << lastName;

    inData.close();
    outData.close();
    return 0;

    But now... How do I use hex table to get data file in to hex..

    }
    unsigned char lower(unsigned char c)
    {
    unsigned char one_byte;
    one_byte = c & 0x0F;
    return one_byte;
    }
    unsigned char upper(unsigned char c)
    {
    unsigned char one_byte;
    one_byte = (c & 0xF0) >> 4;
    return one_byte;
    }

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Uh, show something relevant? Your posts have absolutely nothing to do with an attempt at coding this yourself in either language. Kick me in the teeth for a gift and then ask for me to give you more? Good luck.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. programm will not start
    By keeper in forum C++ Programming
    Replies: 11
    Last Post: 07-03-2006, 06:02 AM
  2. windowsAPI programm
    By datainjector in forum Windows Programming
    Replies: 8
    Last Post: 03-11-2003, 11:08 PM
  3. hexdump issues
    By daluu in forum C Programming
    Replies: 2
    Last Post: 03-04-2003, 09:01 PM
  4. Hexdump...?
    By ylph82 in forum C Programming
    Replies: 5
    Last Post: 06-04-2002, 12:33 AM
  5. I am looking for a programm!
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 04-10-2002, 11:51 AM