OCRudoku  v1.0
Resolve word grid with ease
Loading...
Searching...
No Matches
gridResolver.c File Reference
#include "gridResolver.h"
#include <err.h>
Include dependency graph for gridResolver.c:

Functions

void toUppercase (char *word)
 
void printCoordinates (int startRow, int startCol, int endRow, int endCol)
 
int readFromFile (const char *filename, char ***board, int *boardSize, int **boardColSize)
 
int findCoordinates (char **board, int boardSize, int *boardColSize, const char *word, int *startRow, int *startCol, int *endRow, int *endCol)
 

Function Documentation

◆ findCoordinates()

int findCoordinates ( char ** board,
int boardSize,
int * boardColSize,
const char * word,
int * startRow,
int * startCol,
int * endRow,
int * endCol )

Finds the coordinates of a word in the board.

This function searches for a given word in a 2D character array (board). If the word is found, it sets the starting and ending coordinates of the word in the board. The search is performed in all 8 possible directions: right, down, diagonal down-right, diagonal up-right, left, up, diagonal up-left, and diagonal down-left.

Parameters
boardA 2D character array representing the board.
boardSizeThe number of rows in the board.
boardColSizeAn array representing the number of columns in each row of the board.
wordThe word to search for in the board.
startRowA pointer to an integer to store the starting row index of the word.
startColA pointer to an integer to store the starting column index of the word.
endRowA pointer to an integer to store the ending row index of the word.
endColA pointer to an integer to store the ending column index of the word.
Returns
1 if the word is found, 0 otherwise.

◆ printCoordinates()

void printCoordinates ( int startRow,
int startCol,
int endRow,
int endCol )

Prints the coordinates of the start and end points.

This function takes the starting and ending row and column indices and prints them in the format (startCol,startRow)(endCol,endRow).

Parameters
startRowThe starting row index.
startColThe starting column index.
endRowThe ending row index.
endColThe ending column index.

◆ readFromFile()

int readFromFile ( const char * filename,
char *** board,
int * boardSize,
int ** boardColSize )

Reads a grid from a file and initializes the board.

This function opens a file containing a grid, reads its contents, and initializes the board and its dimensions. The grid must be at least 5x5. Memory is allocated for the board and its column sizes.

Parameters
filenameThe name of the file to read the grid from.
boardA pointer to the 2D character array (grid) to be initialized.
boardSizeA pointer to an integer to store the number of rows in the grid.
boardColSizeA pointer to an integer array to store the number of columns in each row.
Returns
1 if the grid is successfully read and initialized, 0 otherwise.

◆ toUppercase()

void toUppercase ( char * word)

Converts a given word to uppercase.

This function takes a string (character array) as input and converts all lowercase alphabetic characters to their uppercase equivalents. The conversion is done in place, modifying the original string.

Parameters
wordA pointer to the character array (string) to be converted.