我正在尝试编写一个程序,其中将有两个带有大代码块的函数。每个函数都将调用一些较小的函数。现在,在主程序体中,我需要调用两个较大的函数。我在程序中使用数组。
我做了一个样本,但我遇到了错误。请纠正我的代码。我是这个领域的新手。所以请帮忙。
# include <stdio.h>
unsigned char a[4] = {5, 3, 6, 2};
unsigned char b[4] = {3, 5, 2, 5};
unsigned char c[4] = {4, 2, 5, 7};
unsigned char x[4];
unsigned char y[4];
void add(unsigned char* num1, unsigned char* num2, unsigned char* num3)
{
int k;
for (k=0; k<3; k++)
{
num3[k] = num1[k] + num2[k]);
}
}
void mul(unsigned char* num1, unsigned char* num2, unsigned char* num3)
{
int k;
for (k=0; k<3; k++)
{
num3[k] = num1[k] * num2[k]);
}
}
void test1(unsigned char* num1, unsigned char* num2, unsigned char* num3)
{
add(num1, num2, num3);
mul(num1, num2, num3);
}
void test2(unsigned char* num1, unsigned char* num2)
{
add(num1, num2, num1);
}
void main()
{
int i,j ;
test1(a,b,x);
test2(c,y);
for (i=0; i<4; i++)
{
printf("%d ",(x[i]);
}
printf(" ");
for (i=0; i<4; i++)
{
printf("%d ", y[i]);
}
}