I have a function which accepts a void*
pointer as an argument: f(int type, void* data)
.
Then I convert the data value to uint8_t
, process it and try to give back the value to data. I have no idea how to do it.
here is my code:
void CostAccumulator(ProductInfo *product, void *data){
uint8_t amount = 3;
uint8_t _saldo = *((uint8_t*)data);
uint8_t _product_price = product->price;
if(_saldo < _product_price){
do{
_saldo += amount;
printf("%d
",_saldo);
} while (_saldo <= _product_price);
_saldo -= _product_price;
// *data = _saldo;
} else {
printf("%d minus
", _product_price);
_saldo -= _product_price;
// *(*)data) = _saldo;
}
}
Ii is just code for showing void pointers... From School
Please help.
question from:
https://stackoverflow.com/questions/65642982/write-data-back-to-a-void-pointer-argument 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…