2013-08-29 33 views
1

我無法找到解決此錯誤的問題..我嘗試了所有我能想到的方法,並查看了網上的一些示例。但我仍然卡住!錯誤:將複合表達式列表視爲複合表達式

感謝

錯誤:初始化表達式列表被看作複合表達式

unsigned char mbuffer[16]; 

int bcd_encode(32768UL, &mbuffer[0], 4); <---- error is on this line 



------------------------------------------------- 

/* Encode the input number into BCD into the output buffer, of 
* the specified length. The BCD encoded number is right-justified 
* in the field. Return the number of digits converted, or -1 if the 
* buffer was not big enough for the whole conversion. 
*/ 
int bcd_encode(unsigned long number, unsigned char *cbuffer, int length) 
{ 
    unsigned char *p; 
    unsigned char n, m, bval, digit; 

    n = 0;  /* nibble count */ 
    m = 0;  /* converted digit count */ 
    bval = 0; /* the bcd encoded value */ 


    /* Start from the righthand end of the buffer and work 
    * backwards 
    */ 
    p = cbuffer + length - 1; 
    while (p >= cbuffer) { 

     if (number != 0) { 
      digit = number % 10; 
      number = number/10; 
      m++; 
     } else 
      digit = 0; 

     /* If we have an odd-numbered digit position 
     * then save the byte and move to the next buffer 
     * position. Otherwise go convert another digit 
     */ 
     if (n & 1) { 
      bval |= digit << 4; 
      *p-- = bval; 
      bval = 0; 
     } else 
      bval = digit; 

     n++; 
    } 

    /* If number is not zero, then we have run out of room 
    * and the conversion didn't fit. Return -1; 
    */ 
    if (number) 
     return(-1); 

    /* return the number of converted digits 
    */ 
    return(m); 
} 
+0

刪除INT與內部錯誤的行功能與否?它是指一個函數原型還是一個函數調用?解釋你認爲錯誤應該做什麼。 – john

回答

0

您在通話前一個孤獨的int,這不是有效的。

它應該是:

const int numDigits = bcd_encode(32768UL, &mbuffer[0], 4); 
0

爲什麼在函數原型存在價值?

應該是:

int bcd_encode(unsigned long number, unsigned char *cbuffer, int length); 

或者,如果你想使該函數的調用,請執行開卷說,從一開始

+0

是的,我現在看到了我的愚蠢錯誤......謝謝 – user928108