Solved

Urgent - Print contents of a Structure

Posted on 2003-12-01
9
278 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
[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
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 1

Expert Comment

by:Gratch06
ID: 9853664
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
ID: 9853830
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
ID: 9853896
// 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:Triskelion
ID: 9853948
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
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 250 total points
ID: 9855539
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
ID: 9862704
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
ID: 9864481
thankx
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9864482
and waiting for the points
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 9869240
OK
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

719 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