一起添加结构的两个成员

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

但是,我无法弄清楚如何将两者加在一起..(旁注:我知道我不应该像那样使用malloc并使用更明确的方式来做它,但是,我只是想弄清楚此刻的补充)

 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];