我的C代码怎么了? [英] What's wrong with my C-code?

查看:114
本文介绍了我的C代码怎么了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在z/os大型机中工作时,我遇到以下情况.我无法记录交易. 这是我的代码, 它是使用jcl为事务编写的.伯出事了.

Working in z/os mainframe, I have the following situation. I can't record a transaction. here is my code, it is written for transaction using jcl. Bur something goes wrong.

/* Include standard C header files */           
 #include <ctype.h>               
 #include <stdio.h>               
 #include <stdlib.h>              
 #include <string.h>                            
 /* Include WebSphere MQ API header file */      
 #include <cmqc.h>                              
 /* Boolean constants */          
 #define TRUE  1                  
 #define FALSE 0                               
 /* Function prototypes */        
 void displayUsage (char *programName);          
 void displayMQError (char *message, MQLONG compCode, MQLONG reason);    
 double parseAmount (char *amountString);          
 /* Main Program                */

int main (int argc, char *argv[])
 {        
   /* Variable definitions */     
   double   paymentAmount;                     /* Payment amount       */

   MQBYTE   msgBuffer[1024];                   /* Buffer for messages  */

   MQCHAR*  qmgrName;  /* Queue manager name   */ 
   MQCHAR*  requestQueueName;                  /* Request queue name   */ 
   MQCHAR*  replyQueueName;                    /* Reply queue name     */ 
   MQCHAR*  userID;    /* Contestant user ID   */ 
   MQCHAR*  paymentDescription;                /* Payment description  */ 

   MQGMO    getMsgOptions = {MQGMO_DEFAULT};   /* Get options          */ 

   MQHCONN  hConn = MQHC_UNUSABLE_HCONN;       /* Connection handle    */ 

   MQHOBJ   requestHObj = MQHO_UNUSABLE_HOBJ;  /* Request queue handle */ 
   MQHOBJ   replyHObj = MQHO_UNUSABLE_HOBJ;    /* Reply queue handle   */ 

   MQLONG   compCode;  /* API completion code  */ 
   MQLONG   openOptions;                       /* Open queue options   */ 
   MQLONG   reason;    /* API reason code      */ 
   MQLONG   replyMsgLength = 0;                /* Reply msg length     */ 

   MQMD     requestMsgDesc = {MQMD_DEFAULT};   /* Message descriptor   */
   MQMD     replyMsgDesc = {MQMD_DEFAULT};     /* Message descriptor   */

   MQOD     requestQueueDesc = {MQOD_DEFAULT}; /* Object descriptor    */
   MQOD     replyQueueDesc = {MQOD_DEFAULT};   /* Object descriptor    */

   MQPMO    putMsgOptions = {MQPMO_DEFAULT};   /* Put options          */

   /*****************************************/   
   /* Initialisation and parameter checking */   
   /*****************************************/   

   printf ("********************************************************\n");
   printf ("Credit card payment unit test tool\n");
   printf ("********************************************************\n");
   printf (" \n");                

   switch (argc)  
   {      
     case 7  : qmgrName         = argv[1];       
               requestQueueName = argv[2];       
               replyQueueName   = argv[3];       
               userID           = argv[4];       

               paymentAmount = parseAmount (argv[5]);                    

               if ( ( paymentAmount < 0.01 )     
                 || ( paymentAmount > 9999.99 ) )
               {                  
                 printf ("The payment amount must be a valid numeric " \ 
 "within the range 0.01 to 9999.99\n");          

                 displayUsage (argv[0]);         
                 return (1);      
               }                  

               paymentDescription = argv[6];     

               if ( ( strlen (paymentDescription) < 1 )                  
                 || ( strlen (paymentDescription) > 35 ) )               
               {                  
                 printf ("The payment description must be 1-35 " \       
 "characters\n");        

                 displayUsage (argv[0]);         
                 return (1);      
               }                  

               break;             

     default : printf ("Incorrect usage!\n");    
               displayUsage (argv[0]);           
               return (1);        
   }      

   printf ("You have requested a payment of %.2f with description " \    
           "'%s' for contestant %s\n", paymentAmount,                    
           paymentDescription, userID);          

   printf (" \n");                

你能帮我吗? 我不知道如何编写我的Parm参数...

Can you help me? I don't know how to write my Parm parameters...

推荐答案

遇到问题时,请尝试通过程序将所有输出跟踪回输入.

When you have a problem, try to track all the outputs back to the inputs via the program.

其他问题之一:

********************************************************                        
Credit card payment unit test tool                        
********************************************************                        

Incorrect usage!                                                                

Program Usage                                                                   
-------------                                                                   

PAYMENT <queue manager> <cics request queue> <reply queue> <userid> <payment value> <payment description>

The payment description has a maximum length of 35 characters.                  

The monetary value must be within the range 0.01 - 9999.99

前两行很容易解释.最后两行不是这样.他们在那里眨眼,因为确切的文字出现在程序中.但是,似乎在displayUsage函数中使用了完全相同的文本.

The first two lines are easy to explain. The last two lines, not so. They are there to blinker us, as that exact text appears in the program. However, it seems that the exact same text is used in the displayUsage function.

在不同的错误情况下显示相同的文本很不好.这就是我们使用消息编号的原因-消息可能相同,但是消息编号将准确标识消息的来源.

It is bad to display identical text in different error circumstances. That's why we use message numbers - the message may then be the same, but the number will identify exactly where it has come from.

一个提示是,您甚至无法获得一个非常简单的PARM来接受.

A clue is that you can't even get a very simple PARM to be accepted.

另一个线索是Incorrect usage!.

何时打印该消息?当有七个以外的参数时.错...但是您只提供了六个.

When does that message get printed? When there are other than seven parameters. Err... but you only supply six.

因此,如果应该有六个参数,则该程序是错误的.如果您应该提供七个参数,则您的PARM错误.

So, if there are supposed to be six parameters, the program is wrong. If you should be supplying seven parameters, your PARM is wrong.

您可以通过

// PARM='A,B,C,D,1,F,G'

那行得通.

顺便说一句,为什么仍然使用switch而不是简单的if?使用if会使问题更加明显.

As an aside, why was switch used instead of a simple if anyway? Using if would have made the problem more obvious.

这篇关于我的C代码怎么了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆