Pregunta

So I found this library called libsha1, and I wrote a simple program to test it. When I go to compile it with gcc -lsha1 -o sha1sum sha1sum.c, however, it gives me the following error:

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.)

What am I doing wrong? Here's the code:

#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]);
}
¿Fue útil?

Solución

You haven't defined the variable called byte on line 30. Perhaps you meant to use the loop variable i?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top