gpt4 book ai didi

c - 为什么我会收到函数参数的未声明错误? (C)

转载 作者:太空宇宙 更新时间:2023-11-04 07:29:35 26 4
gpt4 key购买 nike

于是我找到了这个叫做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]);
}

最佳答案

您还没有在第 30 行定义名为 byte 的变量。也许您打算使用循环变量 i

关于c - 为什么我会收到函数参数的未声明错误? (C),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15105858/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com