0

そこで libsha1 というライブラリを見つけ、それをテストする簡単なプログラムを書きました。ただし、でコンパイルするとgcc -lsha1 -o sha1sum sha1sum.c、次のエラーが表示されます。

sha1sum.c: In function 'main':
sha1sum.c:30: error: 'byte' undeclared (first use in this function)
sha1sum.c:30: error: (Each undeclared identifier is reported only once
sha1sum.c:30: error: for each function it appears in.)

私は何を間違っていますか?コードは次のとおりです。

#include <stdio.h>
#include <string.h>
#include <libsha1.h>

void printByte(unsigned char);

int main(int argc, char *argv[])
{
        unsigned char hash[20];
        int i;

        #ifndef LIBSHA1_NO_CTX
                sha1_ctx ctx;
        #endif

        if (argc != 2)
        {
                fprintf(stderr, "Usage: %s string\n", argv[0]);
                return 1;
        }

        #ifdef LIBSHA1_NO_CTX
                sha1(hash, argv[1], strlen(argv[1]));
        #else
                sha1_begin(&ctx);
                sha1_hash(argv[1], strlen(argv[1]), &ctx);
                sha1_end(hash, &ctx);
        #endif

        for (i=0; i<5; i++) printByte(byte); printf("\n");

        return 0;
}

void printByte(unsigned char byte)
{
        const char *digits = "0123456789abcdef";
        printf("%c%c", digits[byte / 16], digits[byte % 16]);
}
4

1 に答える 1

3

30 行目で呼び出された変数が定義されていませんbyte。おそらく、ループ変数を使用するつもりでしたiか?

于 2013-02-27T06:53:07.537 に答える