more investigation of c90 compliance and dos compatibility

This commit is contained in:
Greg Gauthier 2026-01-26 20:24:11 +00:00
parent af0affe662
commit 83b2988509
5 changed files with 15 additions and 8 deletions

View File

@ -6,7 +6,13 @@
#define MAX_FILENAME 256
#define MAX_MESSAGE 256
#define MAX_WORDS 10000
/* Reduce MAX_WORDS for DOS to avoid stack overflow */
#ifdef PLATFORM_DOS
#define MAX_WORDS 2000
#else
#define MAX_WORDS 10000
#endif
#define WORD_LENGTH 5
#define MAX_GUESSES 6

View File

@ -36,9 +36,10 @@ void init_game(GameState *game) {
/* Check guess against target word */
void check_guess(GameState *game, const char *guess, int *colors) {
int i, j;
char target_copy[WORD_LENGTH + 1];
char guess_copy[WORD_LENGTH + 1];
int i, j;
int target_used[WORD_LENGTH] = {0};
strcpy(target_copy, game->target_word);
@ -46,7 +47,7 @@ void check_guess(GameState *game, const char *guess, int *colors) {
/* Ensure uppercase */
for (i = 0; i < WORD_LENGTH; i++) {
guess_copy[i] = toupper(guess_copy[i]);
guess_copy[i] = toupper((unsigned char)guess_copy[i]);
}
/* Initialize all as absent */
@ -97,7 +98,7 @@ int make_guess(GameState *game, const char *guess) {
strcpy(upper_guess, guess);
for (i = 0; i < WORD_LENGTH; i++) {
upper_guess[i] = toupper(upper_guess[i]);
upper_guess[i] = toupper((unsigned char)upper_guess[i]);
}
if (!is_valid_word(game, upper_guess)) {

View File

@ -196,7 +196,7 @@ int main_game_loop(int argc, char *argv[]) {
}
} else if ((key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z')) {
if (game.current_guess_length < WORD_LENGTH) {
game.current_guess[game.current_guess_length] = toupper(key);
game.current_guess[game.current_guess_length] = toupper((unsigned char)key);
game.current_guess_length++;
game.current_guess[game.current_guess_length] = '\0';
strcpy(message, "");

View File

@ -143,7 +143,7 @@ void draw_message(WINDOW *win, const char *message, const int y, const int color
/* Draw game instructions */
void draw_instructions(WINDOW *win, int y) {
const char *instructions[] = {
static const char *instructions[] = {
"Guess the 5-letter word in 6 tries!",
"",
"Colors: GREEN=Correct, YELLOW=Wrong position, RED=Not in word",

View File

@ -11,7 +11,7 @@
#include <ctype.h>
/* Try to open a wordlist file, using multiple fallback locations */
static FILE* open_wordlist(const char *filename) {
static FILE *open_wordlist(const char *filename) {
FILE *file;
char filepath[512];
#if HAS_HOME_ENV
@ -47,7 +47,7 @@ static FILE* open_wordlist(const char *filename) {
void to_upper(char *str) {
int i;
for (i = 0; str[i]; i++) {
str[i] = toupper(str[i]);
str[i] = toupper((unsigned char)str[i]);
}
}