i have tried to write this hexdump code for dumping the contents of a tex file.

#include <iostream>
#include <fstream>
#include <string.h>

using namespace std;

int main()
  string line;
  string finline;
  char infile[100];
  char ofile[100];
  char chars[750];

  cout<<"Enter input file: ";
  cin.getline(infile, 99);
  cout<<"Enter output file: ";
  cin.getline(ofile, 99);

  ofstream out;

  ifstream file(infile);

  while(getline(file, line))
    finline += line;
    for(int i = 0; i < finline.size(); i++)
      chars[i] = finline[i];

  for(int i = 0; i < finline.size(); i++)
    chars[i] = finline[i];


  return 0;

but it only give 1 line eg. 0b3d6fc9
and not as much as i think it should.

the file contains 3 lines of data, cant think that 3 lines can be in that 1 little hex line.

Anyway please help me write 1 that will work for dumping contents of files and maby even system memory, the files one is more important at the moment.


Recommended Answers

All 2 Replies

You need to loop the chars array. Something like:

for (int i = 0; i < finline.size(); ++i) {
   cout << hex << chars[i];

Still doesnt work, now it doesnt want to print anything

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.