MᏫᎻᎯᎷᎷᎬᎠ
It's all because a leading software companies They determine what is done and what is not for their self benefits
Anonymous
Thanks
Henry
Which
The very first thing that any software developer has to learn is searching in internet.
MᏫᎻᎯᎷᎷᎬᎠ
Libraries can be developed to ease and speed up the development time
Henry
Just google stuff you want to learn (e.g. you have an error or need to learn something), analyze what you get and solve your problems on your own.
Henry
That is what are software engineers paid for.
Henry
I have learned
Well, I wish you good luck!
Anonymous
Yes
PO
guys need your help
PO
with these 2 loops I can rotate 180° my matrix for(unsigned int i = 0; i < raw; i++){ for(unsigned int j = 0; j < column; j++){ rotate_matrix[i][j] = old_matrix[raw - 1 - i][column - 1 -j]; } }
PO
how can I do the same If I want write my loop like that : for(unsigned int i = raw; i >=0 ;i--){ for(unsigned int j = column; j >= 0 ;j--){ "I don't know what should I put here!😭 " } }
PO
I have tried that but it doesn't work (" rotate_matrix[raw-i-1][column-j-1] = old_matrix[i-1][j-1]; ")
Dexter
what is that "auto"?
It will automatically inherit the type of datatype used from the initializer
Anonymous
There is an other way to do that?
for (auto i = row; i != 0 ; --i) { for (auto j = column; j != 0 ; --j) { and then using [i - 1] and [j - 1] wherever needed
Anonymous
ok thank you
also, in C++ you should use != in tests unless you absolutely need to use something else. this keeps consistency with comparisons when you use non-random access iterators
Anonymous
Thank you anyway
auto was for C++. in C auto currently means automatic variable.
PO
auto was for C++. in C auto currently means automatic variable.
oh shit, so I can't use what you told me
Anonymous
oh shit, so I can't use what you told me
just use unsigned int in place of auto like you were already doing
PO
But I don't know what I have to put in corps of my loop
Anonymous
But I don't know what I have to put in corps of my loop
what's the problem with rotate_matrix[i][j] = old_matrix[row - 1 - i][column - 1 - j];?
Anonymous
PO
you are doing something wrong
It's working but I have to find an other way too
PO
wdym?
I've to find out what should I put inside my loop's corps when I write my loop like that: for(unsigned int i = raw; i >=0 ;i--){ for(unsigned int j = column; j >= 0 ;j--)
Anonymous
I've to find out what should I put inside my loop's corps when I write my loop like that: for(unsigned int i = raw; i >=0 ;i--){ for(unsigned int j = column; j >= 0 ;j--)
change it to for (unsigned int i = row; i >= 0; i--) { if (i == row) { continue; } for (unsigned int j = column; j >= 0; j--) { if (j == column) { continue; }
PO
Is it a function in stdio.h?
Anonymous
What does it mean continue?
in a for loop continue means run the loop expression, then test the loop condition
Anonymous
Anonymous
What does it mean continue?
but this code is terrible. if row is equal to 0, this will be an infinite loop
Anonymous
so you have to do
Anonymous
for (unsigned int i = row; i >= 0; i--) { if (row == 0) { break; } if (i == row) { continue; } for (unsigned int j = column; j >= 0; j--) { if (column == 0) { break; } if (j == column) { continue; }
Anonymous
which is even more terrible. while it fixes the infinite loop, the code is getting messier and messier
Anonymous
soooooooo
PO
do not write a loop like this in the first place
I have to find on other way because my teacher is asking
PO
Dexter
there isn't an other way?
there is.... just replace auto with the expected data type
Dexter
You mean unsigned int yep?
i am talking in general for auto keyword
Dexter
PO
depends on code
normally I use unsigned int
Dexter
normally I use unsigned int
then replace auto with unsigned int
Dexter
👍
PO
👍
for(unsigned int i = raw; i >=0 ;i--){ for(unsigned int j = column; j >= 0 ;j--){ rotate_matrix[i-1][j-1] = old_matrix[i][j]; } }
PO
I get segmentation fault
Anonymous
write the loop as for (auto i = row; i-- != 0;) { for (auto j = column; j-- != 0;) {
1 for (unsigned int i = row; i-- > 0;) { for (unsigned int j = column; j-- > 0;) { rotate_matrix[i][j] = old_matrix[row - 1 - i][column - 1 - j]; } }
Anonymous
for (auto i = row; i != 0 ; --i) { for (auto j = column; j != 0 ; --j) { and then using [i - 1] and [j - 1] wherever needed
2 for (unsigned int i = row; i > 0; --i) { for (unsigned int j = column; j > 0; --j) { rotate_matrix[i - 1][j - 1] = old_matrix[row - i][column - j]; } }
PO
I'm trying
PO
0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
PO
for (unsigned int i = raw; i > 0; i--) { for (unsigned int j = column; j > 0; j--) { rotate_matrix[i - 1][j - 1] = old_matrix[raw - i][column - j]; } }
Anonymous
I get segmentation fault
that's likely a fault in your code and not in the 4 lines i wrote
PO
same with this
the same code works with : for(unsigned int i = 0; i < raw; i++){ for(unsigned int j = 0; j < column; j++){ rotate_matrix[i][j] = old_matrix[raw - 1 - i][column - 1 -j]; } }
Anonymous
Anonymous