#ifndef IO_H #define IO_H #include "utils.h" #include #include /** * @brief Reads a line from the given stream, dynamically allocating memory for the line. * The line is terminated by a newline character or EOF. If a '#' character is encountered, the rest of the line is ignored (treated as a comment). * @param stream The input stream to read from (e.g., stdin or a file). * @param msgptr Pointer to a char pointer that will hold the address of the allocated string. If *msgptr is NULL, memory will be allocated for the string. * @param n Pointer to a size_t variable that will hold the size of the allocated string. If *msgptr is NULL, *n will be set to 128 initially and will be doubled as needed. * @return 0 on success, 1 on error (e.g., if msgptr or n is NULL, or if memory allocation fails). If the end of the file is reached before any characters are read, it also returns 1. */ bool read_line(FILE* stream, char** msgptr, size_t* n); /* * @brief Reads three 128 bit integers from the user with a prompt * @param prompt The message to display to the user before reading input * @param a Pointer to store the first integer * @param b Pointer to store the second integer * @param c Pointer to store the third integer * @return 0 on success, -1 on printf error, -2 on scanf error */ int read_int128_triplet(const char* prompt, int128_t* a, int128_t* b, int128_t* c); /* * @brief Converts a string to a 128 bit integer * @param s The string to convert * @return The converted 128 bit integer */ int128_t str_to_int128(const char* s); /** * @brief Prints a 128 bit integer * @param n The integer to print */ void print_int128(int128_t n); #endif