Solved

Pretty the output? Floppy dump to screen program

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Concatenate two strings Last and First Name 10 59
Detect CR LF to each line 12 153
Socket Programming (Unix) 8 119
Digital Output does not have continuity to ground? 3 84
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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 how to create, access, and change arrays in the C programming language.

895 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

17 Experts available now in Live!

Get 1:1 Help Now