/* * jims_utils.h * Various utility functions in C * Jim Mahoney | cs.marlboro.edu | March 2011 | GPL */ #include #include #include #include // versions of C functions that exit with error if they fail. void* malloc_safe(size_t size); void* calloc_safe(size_t count, size_t element_size); FILE* fopen_safe(const char* filename, const char* mode); // Read in a whole file and return a pointer to a buffer with its contents. char* slurpfile(char* filename); // Convert integer to character string (i.e. 2 to "2") // (Note that the opposite iint=atoi(char*) is in stdlib.h char* itoa(int i); // Search starting at text[*offset] for next word // (made up of lower or uppercase letters only), and copy // it to word[]. If a word is found, return 1. *offset is // modified to be the index of the character after the word // found, so that getnextword() can be run repeatedly. // If no word is found, or the end of the text string is reached, // or the size of the word is larger than maxsize, return 0. int getnextword(char* text, int* offset, char* word, int maxsize);