A possible error in the book
The question's code works for AES-128 and AES-256, but indeed does not for AES-192, for the reason pointed in the question.

Yes changing if ( !( i % 36 ) ) into if((!(i%36)) &amp;&amp; (key_words == 4)) as suggested in comment by the OP is enough to make it (and the rest of the code) pass the example of appendix A.2 and C.2 of FIPS&nbsp;197 (as well as A.1, A.3, C.1, C.3).

Reminds me of the book Security for Computer Networks by D.W. Davies (not the same Davies) and W.L. Price (May 1987 edition), which has a typo in the last constant for S4 of DES, causing failures for some test vectors. That drove me nuts for a while in the late 1980s. From that point on I implemented crypto on the basis of the standards.