Solved

Pretty the output? Floppy dump to screen program

Posted on 2002-04-23
5
227 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now