I have a very simple piece of code and it reads characters from files. If the index y iterates from low to high, everything works. But, if it iterates from high to low (the commented line), it gives me the seg fault problem. Could someone explain why this happens? Thank you!
void read_ct_from_file( unsigned char** ct, const size_t row, const size_t column, FILE* inf ) {
size_t x, y;
for( x = 0; x < row; x++ ) {
for( y = 0; y < column; y++ ) {
//for( y = column - 1; y >= 0; y-- ) { // iterate from high to low
fscanf( inf, "%02x", &ct[x][y] );
printf( "%02x ", ct[x][y] );
}
printf( "\n" );
}
}
size_tis unsigned, so your loop will aftery = 0continue withmax_unsignedwhich is >= 0.