Stergios Upload Compile Checker / Explore-Gitea-Actions (push) Successful in 7s
56 lines
2.2 KiB
C
Executable File
56 lines
2.2 KiB
C
Executable File
#ifndef IO_H
|
|
#define IO_H
|
|
|
|
#include "utils.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
/**
|
|
* @brief Prompts the user for a line of input, handling both interactive and non-interactive modes.
|
|
* @param prompt The message to display to the user before reading input
|
|
* @return A dynamically allocated string containing the user's input. The caller is responsible for freeing this.
|
|
*/
|
|
char* prompt_line(const char* prompt);
|
|
|
|
/**
|
|
* @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 output The file pointer to print to (e.g., stdout or a file)
|
|
* @param n The integer to print
|
|
*/
|
|
void fprint_int128(FILE* output, int128_t n);
|
|
|
|
/**
|
|
* @brief Prints a 128 bit integer
|
|
* @param n The integer to print
|
|
*/
|
|
void print_int128(int128_t n);
|
|
|
|
#endif |