Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Pretty the output? Floppy dump to screen program

Posted on 2002-04-23
5
Medium Priority
?
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 800 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
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…
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 opening and reading files in the C programming language.
Suggested Courses

609 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