Solved

Urgent - Print contents of a Structure

Posted on 2003-12-01
9
276 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adapt this command to show who installed 29 111
Macro to save highlighted rows as a separate file 5 45
unable to delete all specified values regedit 38 576
Detect file exist or not 3 181
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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