• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

Pretty the output? Floppy dump to screen program

I have the following program source code that dumps the contents of a floppy sector to the screen.  The source code is here: http://stealth.kirenet.com/~aleinss/diskdump.cpp  I
would like to have a cleaner output like this:
http://stealth.kirenet.com/~aleinss/floppy_2.jpg
with the pretty hex offsets and such, can anyone help?

Thanks,
Adam
0
Adam Leinss
Asked:
Adam Leinss
  • 2
  • 2
1 Solution
 
elfieCommented:
in the dumpsector routine, you have to write two loops:
a first loop printing out the value in hex "%3.3x ", and a second loop as you have now.
0
 
Adam LeinssSenior Desktop EngineerAuthor Commented:
Hi.

Unforunately, it's a tad more complex than that.  I want the hex to run left to run and then have the text in the last column, with the cool offsets.  Ok, it doesn't have to have the xxx offsets on the left, they can run 3 characters across, but I need some code to play with.

I'll ante up the points to 400, 200 now and 200 later.
0
 
zebadaCommented:
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define BYTES_PER_LINE   16
#define MIN(a,b) (((a)<(b))?(a):(b))

char *dump(char *buf, int bufLen);

int
main(int argc, char *argv[])
{
  int i,len;
  char *buf = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\001\002\003\004\005ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";

  len = 26*3+5;
  for ( i=0 ; i<len ; i+=BYTES_PER_LINE ) {
    printf("%s\n",dump(buf+i,MIN(BYTES_PER_LINE,len-i)));
  }

  return 0;
}

char *
dump(char *buf, int bufLen)
{
  static char txt[BYTES_PER_LINE*4+3+1];

  int  i;
  char tmp[4];
  char hex[BYTES_PER_LINE*3+1];
  char asc[BYTES_PER_LINE+1];

  char *h=hex;
  char *a=asc;

  for ( i=0 ; i<bufLen ; i++ ) {
    sprintf(tmp,"%02.2X ",*buf);
    strcpy(h,tmp);
    h += 3;

    *a++ = isprint(*buf)?*buf:'.';
    buf++;
  }  
  *a = '\0';
  sprintf(txt,"%-*s | %s",BYTES_PER_LINE*3,hex,asc);
  return txt;
}

Output is:

41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50  | ABCDEFGHIJKLMNOP
51 52 53 54 55 56 57 58 59 5A 01 02 03 04 05 41  | QRSTUVWXYZ.....A
42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51  | BCDEFGHIJKLMNOPQ
52 53 54 55 56 57 58 59 5A 41 42 43 44 45 46 47  | RSTUVWXYZABCDEFG
48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57  | HIJKLMNOPQRSTUVW
58 59 5A                                         | XYZ
0
 
Adam LeinssSenior Desktop EngineerAuthor Commented:
Thanks, looks exactly what I need, I'll open another question for ya
0
 
zebadaCommented:
No don't worry about the extra points 200 is more than enough. :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The IT Degree for Career Advancement

Earn your B.S. in Network Operations and Security and become a network and IT security expert. This WGU degree program curriculum was designed with tech-savvy, self-motivated students in mind – allowing you to use your technical expertise, to address real-world business problems.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now