Solved

Pretty the output? Floppy dump to screen program

Posted on 2002-04-23
5
230 Views
Last Modified: 2011-09-20
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
Comment
Question by:Adam Leinss
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:elfie
ID: 6964937
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
 
LVL 22

Author Comment

by:Adam Leinss
ID: 6965961
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
 
LVL 6

Accepted Solution

by:
zebada earned 200 total points
ID: 6967582
#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
 
LVL 22

Author Comment

by:Adam Leinss
ID: 6967643
Thanks, looks exactly what I need, I'll open another question for ya
0
 
LVL 6

Expert Comment

by:zebada
ID: 6967757
No don't worry about the extra points 200 is more than enough. :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question