Solved

Urgent - Print contents of a Structure

Posted on 2003-12-01
9
275 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
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 116
Window placement 17 82
changeXy challenge 13 81
Capture logon name 13 70
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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 quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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