From: Christian Heller Date: Wed, 29 May 2013 01:33:30 +0000 (+0200) Subject: Don't hardcode size of unsigned chars. X-Git-Tag: tce~1271 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/te"st.html?a=commitdiff_plain;h=de16bd61d64e7d2fc87ce283fbd925f68c614bd3;p=plomrogue Don't hardcode size of unsigned chars. --- diff --git a/roguelike.c b/roguelike.c index 7abc323..1dfa627 100644 --- a/roguelike.c +++ b/roguelike.c @@ -1,5 +1,5 @@ #include -//#include +#include #include #include #include @@ -21,7 +21,7 @@ uint16_t rrand(char use_seed, uint32_t new_seed) { uint32_t load_seed() { // Load seed integer from seed file. uint32_t seed; - const uint16_t nchar = 256; + const uint16_t nchar = UCHAR_MAX + 1; FILE * file = fopen("seed", "r"); unsigned char a = fgetc(file); unsigned char b = fgetc(file); @@ -33,7 +33,7 @@ uint32_t load_seed() { void save_seed(uint32_t seed) { // Save seed integer to seed file. - const uint16_t nchar = 256; + const uint16_t nchar = UCHAR_MAX + 1; unsigned char a = seed / (nchar * nchar * nchar); unsigned char b = (seed - (a * nchar * nchar * nchar)) / (nchar * nchar); unsigned char c = (seed - ((a * nchar * nchar * nchar) + (b * nchar * nchar))) / nchar;