typedef struct Int40
{
// a dynamically allocated array to hold a 40
// digit integer, stored in reverse order
int *digits;
} Int40;
在 main 中我实现了这些函数,loadCryptoVariable 和 loadHwConfigVariable 各自返回一个 40 位的值
Int40 *p;
Int40 *q;
Int40 *r;
p = loadCryptoVariable("cryptoVarFile");
q = loadHWConfigVariable(0);
r = kw26Add( p, q);
但是,我无法弄清楚如何将两者相加。弄清楚此刻的添加)
Int40 *kw26Add(Int40 *p, Int40 *q)
{
Int40 *result;
result = malloc(300);
result->digits = malloc(300);
result->digits = p->digits + q->digits;
return result;
}
最佳答案
我不确定我是否理解这个问题,但在我阅读它时,您需要遍历数组。例如:
for (int i = 0; i < 40; ++i)
result->digits[i] = p->digits[i] + q->digits[i];
关于c - 将结构的两个成员相加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49205149/