Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
154 views
in Technique[技术] by (71.8m points)

c - Write data back to a void pointer argument

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...