#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
struct test_s
{
float val ;
int bol ;
} ;
#define LEN 5
struct test_s mystr[LEN] ;
int main( void )
{
for( int i = 0 ; i < LEN ; i += 1 )
{
mystr[i].val = 321.0f ;
mystr[i].bol = 1 ;
}
for( int i = 0 ; i < LEN ; i += 1 )
printf( "\n %f %d" , mystr
[i
].
val , mystr
[i
].
bol ) ;
for( int i = 0 ; i < LEN ; i += 1 )
mystr[i].val = 0.0f ; //set only val to 0
for( int i = 0 ; i < LEN ; i += 1 )
printf( "\n %f %d" , mystr
[i
].
val , mystr
[i
].
bol ) ; //both values get printed as 0, WRONG!
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0ZGJvb2wuaD4KCnN0cnVjdCB0ZXN0X3MKewogICAgZmxvYXQgIHZhbCA7CiAgICBpbnQgYm9sIDsKCn0gOwoKI2RlZmluZSBMRU4gNQoKc3RydWN0IHRlc3RfcyBteXN0cltMRU5dIDsKCmludCBtYWluKCB2b2lkICkKewogICAgZm9yKCBpbnQgaSA9IDAgOyBpIDwgTEVOIDsgaSArPSAxICkKICAgIHsKICAgICAgICBteXN0cltpXS52YWwgPSAzMjEuMGYgOyAKICAgICAgICBteXN0cltpXS5ib2wgPSAxIDsKICAgIH0KCiAgICBmb3IoIGludCBpID0gMCA7IGkgPCBMRU4gOyBpICs9IDEgKQogICAgICAgIHByaW50ZiggIlxuICVmICAgJWQiICwgbXlzdHJbaV0udmFsICwgbXlzdHJbaV0uYm9sICkgOwoKICAgIGZvciggaW50IGkgPSAwIDsgaSA8IExFTiA7IGkgKz0gMSApCiAgICAgICAgbXlzdHJbaV0udmFsID0gMC4wZiA7ICAgLy9zZXQgb25seSB2YWwgdG8gMAoKICAgIGZvciggaW50IGkgPSAwIDsgaSA8IExFTiA7IGkgKz0gMSApCiAgICAgICAgcHJpbnRmKCAiXG4gJWYgICAlZCIgLCBteXN0cltpXS52YWwgLCBteXN0cltpXS5ib2wgKSA7ICAvL2JvdGggdmFsdWVzIGdldCBwcmludGVkIGFzIDAsIFdST05HIQoKICAgIHJldHVybiAwOwp9