#include <stdio.h> int oem_add(void *in) { *in += 10; } int main() { int b = 0; oem_print(&b); printf("%d\n", b); return 0; }
时间: 2023-12-10 07:41:11 浏览: 24
这段代码有一些错误。首先,函数名应该是 `oem_add` 而不是 `oem_print`。其次,在 `main` 函数中调用 `oem_print` 函数时,应该传入的是 `&b` 而不是 `b`。最后,由于 `oem_add` 函数的参数类型是 `void*`,需要先将 `&b` 的类型转换为 `void*`。
下面是修改后的代码:
```
#include <stdio.h>
void oem_add(void *in) {
*(int*)in += 10;
}
int main() {
int b = 0;
oem_add(&b);
printf("%d\n", b);
return 0;
}
```
运行结果为:
```
10
```
相关问题
#include <stdio.h> int oem_print(void *in) { int a = 3; *in = a; printf("%d\n", *in); } int main() { int b = 4; oem_print(&b); return 0; }
这段代码存在问题,因为在oem_print函数中,指针类型的参数in没有声明其指向的数据类型。此外,在oem_print中试图修改指针in所指向的,但是in是一个void类型的指针,不能进行解引用操作。可以尝试修改代码如:
```
#include <stdio.h>
void oem_print(int *in) {
int a = 3;
*in = a;
printf("%d\n", *in);
}
int main() {
int b = 4;
oem_print(&b);
return 0;
}
```
这样修改后,指针in被声明为int类型的指针,并且在函数中可以修改它所指向的值。输出结果为3,表示指针in指向的地址的值已经被修改为3。
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #define SHA1_BLOCK_SIZE 20 #define SHA1_DIGEST_SIZE 5
SHA-1是一种密码散列函数,用于产生消息的数字指纹。SHA-1算法的输出长度为160位,即20个字节。在C语言中,可以使用以下代码来实现SHA-1算法:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#define SHA1_BLOCK_SIZE 20
#define SHA1_DIGEST_SIZE 5
void sha1(const uint8_t *message, size_t message_len, uint8_t *digest) {
// TODO: 实现SHA-1算法
}
int main() {
uint8_t message[] = "hello world";
uint8_t digest[SHA1_DIGEST_SIZE];
sha1(message, strlen((char *)message), digest);
printf("SHA-1 digest: ");
for (int i = 0; i < SHA1_DIGEST_SIZE; i++) {
printf("%02x", digest[i]);
}
printf("\n");
return 0;
}
```
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)