VanDavv/IT-Labs

unique int for every struct

Closed this issue · 3 comments

Requirement was, that for every int field, it's value must be unique .

Consider adding the following code to make it done

do { structs[i]->i = (rand() % 10001) - 1000; present = 0; for (j = 0; (j < i) && (present == 0); ++j) { if (structs[j]->i == structs[i]->i) { present = 1; } } } while (present == 1);

EDIT
Please describe issue mode in detail when submitting ~VanDavv

I'm not really convinced to for loop nested in do-while loop.
I'd rather another array containing already taken int's and checking if picked int is not in that array

do w/e you want

@Tommac1 I've changed the code according to your suggestion, thanks!

See: 422d008#diff-df9ae53d975af01f807194b866b422e9