Urgent - Print contents of a Structure

Hi

How do I print to my printer the all the values in a structure
Dj_Fx8Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gratch06Commented:
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
Dj_Fx8Author Commented:
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
TriskelionCommented:
// 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
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

TriskelionCommented:
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
Roshan DavisCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dj_Fx8Author Commented:
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
Roshan DavisCommented:
thankx
0
Roshan DavisCommented:
and waiting for the points
0
TriskelionCommented:
OK
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.