<commit_before>/* This is a simple dictionary program that uses a text file to store 
 * records of keywords and definitions and allows their lookup. */
 
#include <stdio.h>
#include <stdlib.h>

/* simple dictionary entry structure */
struct entry
{
	char name[20];
	char definition[80];
};

/* takes an open FILE object, loads the dictionary records into an array
 * and returns a pointer to that array */
struct entry *dictLoader (FILE *dictFile)
{
	/* should the dict be global or local to this function?
	 * the returned pointer points to it either way... */
	struct entry dictionary[100];
	struct entry *dictPtr = dictionary;
	char *line = NULL;
	size_t len = 0;
	ssize_t read;
	
	/* read lines into colon-separated name and definition of dictionary 
	 * as entries until end of file */
	while ( ( read = getline (&line, &len, dictFile) ) != -1 )
	{
		static int i = 0;
		sscanf (line, "%[^:]: %[^\n]", dictionary[i].name, dictionary[i].definition);
		i++;
	}
	
	return dictPtr;
}

/* takes a pointer to a dictionary array, looks for a matching word and returns
 * a pointer pointing to it */ 
struct entry *dictLookup (struct entry *dictPtr, const char *keyword)
{
	for ( ; *dictPtr->name != 0; dictPtr++ )
		if ( *dictPtr->name == *keyword )
			return dictPtr;
			
	/* Fall through - no matching key found in dictionary */
	return NULL;
}

int main (const int argc, const char *argv[])
{
	/* function prototypes */
	struct entry *dictLoader (FILE *dictFile);
	struct entry *dictLookup (struct entry *dictPtr, const char *keyword);
	
	/* variable definitions */
	FILE *dictFile;
	struct entry * matchPtr;
	char choice;
	char newDefinition[80];
	
	/* if no arguments are given, print a short help message */
	if ( argc == 1 )
	{
		printf ("No arguments were specified.\n"
				"Use: dictlook <word> [dictionary file]\n\n");
		exit (EXIT_SUCCESS);
	}
	
	/* exit with error if too many arguments were given */
	if ( argc > 3 )
	{
		fprintf (stderr, "Too many arguments were specified: %i\n"
				 "Use: dictlook <word> [dictionary file]\n");
		exit (EXIT_FAILURE);
	}
	
	if ( argc == 2 )
	{
		dictFile = fopen (argv[2], "r+");
		/* if dictionary file doesn't exist, fall back to default */
		if ( dictFile == NULL )
				dictFile = fopen ("words.txt", "r+");
	}
	
	/* can be separated into 2 calls for better clarity */
	matchPtr = dictLookup (dictLoader (dictFile), argv[1]);
	<commit_msg>Change dictionary to global variable and remove redundant pointer.<commit_after>/* This is a simple dictionary program that uses a text file to store 
 * records of keywords and definitions and allows their lookup. */
 
#include <stdio.h>
#include <stdlib.h>

/* simple dictionary entry structure */
struct entry
{
	char name[20];
	char definition[80];
};

struct entry dictionary[100];

/* takes an open FILE object, loads the dictionary records into an array
 * and returns a pointer to that array */
struct entry *dictLoader (FILE *dictFile)
{
	char *line = NULL;
	size_t len = 0;
	ssize_t read;
	
	/* read lines into colon-separated name and definition of dictionary 
	 * as entries until end of file */
	while ( ( read = getline (&line, &len, dictFile) ) != -1 )
	{
		static int i = 0;
		sscanf (line, "%[^:]: %[^\n]", dictionary[i].name, dictionary[i].definition);
		i++;
	}
	
	return dictionary;
}

/* takes a pointer to a dictionary array, looks for a matching word and returns
 * a pointer pointing to it */ 
struct entry *dictLookup (struct entry *dictPtr, const char *keyword)
{
	for ( ; *dictPtr->name != 0; dictPtr++ )
		if ( *dictPtr->name == *keyword )
			return dictPtr;
			
	/* Fall through - no matching key found in dictionary */
	return NULL;
}

int main (const int argc, const char *argv[])
{
	/* function prototypes */
	struct entry *dictLoader (FILE *dictFile);
	struct entry *dictLookup (struct entry *dictPtr, const char *keyword);
	
	/* variable definitions */
	FILE *dictFile;
	struct entry * matchPtr;
	char choice;
	char newDefinition[80];
	
	/* if no arguments are given, print a short help message */
	if ( argc == 1 )
	{
		printf ("No arguments were specified.\n"
				"Use: dictlook <word> [dictionary file]\n");
		exit (EXIT_SUCCESS);
	}
	
	/* exit with error if too many arguments were given */
	if ( argc > 3 )
	{
		fprintf (stderr, "Too many arguments were specified: %i\n"
				 "Use: dictlook <word> [dictionary file]\n");
		exit (EXIT_FAILURE);
	}
	
	if ( argc == 2 )
	{
		dictFile = fopen (argv[2], "r+");
		/* if dictionary file doesn't exist, fall back to default */
		if ( dictFile == NULL )
				dictFile = fopen ("words.txt", "r+");
	}
	
	/* can be separated into 2 calls for better clarity */
	matchPtr = dictLookup (dictLoader (dictFile), argv[1]);
	
{'fraction_non_alphanumeric': 0.1255069370330843, 'fraction_numerical': 0.008110992529348986, 'mean_word_length': 3.479923518164436, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1504881', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1418, 'n_words': 584}