Solved

Urgent - Print contents of a Structure

Posted on 2003-12-01
9
271 Views
Last Modified: 2013-11-20
Hi

How do I print to my printer the all the values in a structure
0
Comment
Question by:Dj_Fx8
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 1

Expert Comment

by:Gratch06
Comment Utility
if your structure is like this, you can do the following....

struct structure_name {
  int element1;
  double element2;
  string element3;
  .
  .
};

structure_name myStruct;
cout << myStruct.element1 << myStruct.element2 << myStruct.element3 << endl;

Obviously, for most applications, you'll need to format that a bit more specifically, but that's a basic example anyway.  Post back if you have further questions.  Please post your struct definition if there are problems.
0
 

Author Comment

by:Dj_Fx8
Comment Utility
Hi
This struct is quite large (> 1k) with many elements, so it would take too long to type out, I was hopeing for a quict way to do this as it's only required for debugging purposes. Ps here's the structure, as you see it's struct within struct within struct

Struct I want to print

typedef struct tag_NERO_WRITE_CD
{
const char *nwcdArtist;
const char *nwcdTitle;
struct CNeroIsoTrack *nwcdIsoTrack;
BOOL nwcdCDExtra;
void *nwcdpCDStamp;
DWORD nwcdNumTracks;
NERO_MEDIA_TYPE nwcdMediaType;
BOOL nwcdAudioMaster;
DWORD nwcdReserved[31];
NERO_AUDIO_TRACK nwcdTracks[1];
} NERO_WRITE_CD;

Other struct contained within the one I want to print

typedef struct tag_NERO_AUDIO_TRACK
{
DWORD natPauseInBlksBeforeThisTrack;
DWORD natNumIndexPositions;
DWORD natRelativeIndexBlkPositions[98];
const char *natTitle, *natArtist;
NERO_DATA_EXCHANGE natSourceDataExchg;  
DWORD natLengthInBlocks;
BOOL natIndex0ContainsData;
DWORD natReserved[31];
} NERO_AUDIO_TRACK;
0
 
LVL 6

Assisted Solution

by:Triskelion
Triskelion earned 250 total points
Comment Utility
// Here's a strange hybrid example.

#include <afx.h>
#include <iostream>
using namespace std;

typedef struct tagMY_STRUC
{
  int      element1;
  double element2;
  string element3;
} MY_STRUC;


void main(void)
{
      auto      FILE*      hanPrinter=NULL;
      auto      MY_STRUC      xxxData;

      if (NULL==(hanPrinter=fopen("lpt1","wb")))
            {
            puts("can't open printer");
            return;
            }

      xxxData.element1=156;
      xxxData.element2=123.45;
      xxxData.element3="5432ABC";

      fprintf(hanPrinter, "Element1=%d\nElement2=%3.3f\nElement3=%s",
            xxxData.element1,
            xxxData.element2,
            xxxData.element3.data()
            );
      fclose(hanPrinter);
}
0
 
LVL 6

Expert Comment

by:Triskelion
Comment Utility
If you're just interested in the bytes, you can dump the whole thing to a file with (yeah, I know... old-school) fwrite() and then load it as a binary file in something like TextPad (which will print).

It will not, however, align the data to the structure for you.

I suppose you've exhausted the "watch window", right?
If you print it and find the bug, the printout is immediately obsolete.
The watch window will allow you to expand and colapse the different elements in the structure.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 23

Accepted Solution

by:
Roshan Davis earned 250 total points
Comment Utility
Yes, I'm expanding Triskelion's way

1. Put a break point in the structure filling code area
2. Run the Application in the Debug mode
3. Right click on the structure object and select "Quick Watch" from the menu
4. Click on the Add watch button of the dialog that popped up when clicking  on Quick Watch
5. Now you can see "Add Watch" window in the botton of the your VC++ editor
6. Expand the strcture tree and select all text using SHIFT Key
7. Paste this data on a notepad/wordpard and Print it

Good luck
0
 

Author Comment

by:Dj_Fx8
Comment Utility
Hi
Thanks for your replies, I guess there's no simple one liners for this but from the info from Triskelion and Roshomon I have got a workable solution, so I'll split the points between you's.
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
thankx
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
and waiting for the points
0
 
LVL 6

Expert Comment

by:Triskelion
Comment Utility
OK
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

9 Experts available now in Live!

Get 1:1 Help Now