Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File definition in VC++

Status
Not open for further replies.

RVP2B

Programmer
Mar 8, 2002
1
US
I need to define and read a file to be used in the following code, how can I do that?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* includes for MQI */
#include <cmqc.h>

int main(int argc, char **argv)
{
/* Declare file and character for sample input */
FILE *fp;

/* Declare MQI structures needed */
MQOD od = {MQOD_DEFAULT}; /* Object Descriptor */
MQMD md = {MQMD_DEFAULT}; /* Message Descriptor */
MQPMO pmo = {MQPMO_DEFAULT}; /* put message options */
/** note, sample uses defaults where it can **/

MQHCONN Hcon; /* connection handle */
MQHOBJ Hobj; /* object handle */
MQLONG o_Options; /* MQOPEN options */
MQLONG C_options; /* MQCLOSE options */
MQLONG CompCode; /* completion code */
MQLONG OpenCode; /* MQOPEN completion code */
MQLONG Reason; /* reason code */
MQLONG CReason; /* reason code for MQCONN */
MQLONG messlen; /* message length */
char buffer[100]; /* message buffer */
char QMName[50]; /* queue manager name */

printf(&quot;Sample GMQSPUT0 start\n&quot;);
if (argc < 2)
{
printf(&quot;Required parameter missing - queue name\n&quot;);
exit(99);
}

/******************************************************************/
/* */
/* Connect to queue manager */
/* */
/******************************************************************/
QMName[0] = 0; /* default */
if (argc > 2)
strcpy(QMName, argv[2]);
MQCONN(QMName, /* queue manager */
&Hcon, /* connection handle */
&CompCode, /* completion code */
&CReason); /* reason code */

/* report reason and stop if it failed */
if (CompCode == MQCC_FAILED)
{
printf(&quot;MQCONN ended with reason code %ld\n&quot;, CReason);
exit( (int)CReason );
}

/******************************************************************/
/* */
/* Use parameter as the name of the target queue */
/* */
/******************************************************************/
strncpy(od.ObjectName, argv[1], (size_t)MQ_Q_NAME_LENGTH);
printf(&quot;target queue is %s\n&quot;, od.ObjectName);

/******************************************************************/
/* */
/* Open the target message queue for output */
/* */
/******************************************************************/
o_Options = MQOO_OUTPUT /* open queue for output */
+ MQOO_FAIL_IF_QUIESCING; /* but not if MQM stopping */
MQOPEN(Hcon, /* connection handle */
&od, /* object descriptor for queue */
o_Options, /* open options */
&Hobj, /* object handle */
&OpenCode, /* MQOPEN completion code */
&Reason); /* reason code */

/* report reason, if any; stop if failed */
if (Reason != MQRC_NONE)
{
printf(&quot;MQOPEN ended with reason code %ld\n&quot;, Reason);
}

if (OpenCode == MQCC_FAILED)
{
printf(&quot;unable to open queue for output\n&quot;);
}

/******************************************************************/
/* */
/* Read lines from the file and put them to the message queue */
/* Loop until null line or end of file, or there is a failure */
/* */
/******************************************************************/
CompCode = OpenCode; /* use MQOPEN result for initial test */
fp = stdin;

memcpy(md.Format, /* character string format */
MQFMT_STRING, (size_t)MQ_FORMAT_LENGTH);


Check me out
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top