How to decide when fread changes the values ​​of other integer variables

I'm having problems in my homework at college, I am coding some sorting methods in C ++, and this happened:

int nufi = 0, d;
cout << "nufi  value: " << nufi << endl;

d  = fread(&item, sizeof(ItemType), 1, stripes[nStripe].arq);

cout << "nufi value: " << nufi << endl;

It was suggested for printing: nufi value: 0 nufi value: 0 but instead prints: nufi value: 0 nufi value: 541151813

Basically, every integer variable that passes through fread is changed;

I tried changing the names of the variables, changing the open files and all those tests that I think, and the error persists, not always with this value, when I change the names of the variables, the number changes too, only when I delete fread, the error disappears.

The rest of the code is fine and tested, opening the file, structures, keys, etc.

Does anyone know what could happen?

+4
1

undefined, . , item ItemType. , fread , .

:

fread( &item, sizeof(item), 1, stripes[nStripe].arq );

, , ItemType*. :

fread( item, sizeof(ItemType), 1, stripes[nStripe].arq );
//     ^ Note reference removed because item is a pointer to ItemType.
+1

Source: https://habr.com/ru/post/1627231/


All Articles