1

このエラーの解決策を見つけるのに苦労しています。考えられることはすべて試し、Web でいくつかの例を調べました。しかし、私はまだ行き詰まっています!

ありがとう

エラー: 複合式として扱われる初期化式リスト

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);
}
4

2 に答える 2

1

関数プロトタイプに値があるのはなぜですか?

次のようにする必要があります。

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

または、その関数を呼び出そうとしている場合は、アンワインドが言ったようにして、最初から int を削除します

于 2013-08-29T14:25:19.810 に答える