Talk:Caesar cipher: Difference between revisions

Correction of C solution - 2019-03-04
(Correction of C solution - 2019-03-04 .)
(Correction of C solution - 2019-03-04)
Line 19:
:Unless there are objections, I propose to restore at least the functional version, so that readers are allowed see both approaches [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 12:11, 4 November 2016 (UTC)
 
==Correction of C solution - 2019-03-04 .==
 
:Compilation of the original program was carried out on Linux, where the implicit function declaration warnings for isalpha, isupper and tolower, are resolved by adding an #include <ctype.h> statement at the top. However, the program crashes at run-time causing a segmentation fault at the point of transforming the first char in the string. The reason for the failure is because the isupper function is only guaranteed to return zero if it fails, and a non-zero value if it passes. On linux this non-zero value is not '1' as the original author may have expected, but '255' (checked the result by using gdb); as such it breaks the idea of using the result of isupper in this fashion to determine which alphabet string (lower or upper) to use as there's only index '0' and '1' in the 'alpha' const char array named 'alpha[2]' and no there's no index at '255' (reason for the seg fault!). This is resolved by using an if statement to test the case of current alpha character and to set the index of 'alpha' array to 0 or 1 accordingly.
Anonymous user