You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.8 KiB
C

// License: AGPLv3 or later. https://www.gnu.org/licenses/licenses.html
#ifndef _GENERAL_FUNCTIONS_H_
#define _GENERAL_FUNCTIONS_H_
#include <string>
#include <vector>
bool is_natural_number(const char* c_str);
bool is_whole_number(const char* c_str);
void get_textfile_lines(
std::string filename, std::vector<std::string> &file_lines);
int random_int(int minimum, int maximum);
float random_float(float minimum, float maximum);
int modulate(int number, int modulus);
void cerr_and_exit(
int exit_code,
std::string error_name,
std::string file_name,
std::string function_name,
int line_number,
std::string additional_message = "");
void cerr_only(
std::string error_name,
std::string file_name,
std::string function_name,
int line_number,
std::string additional_message);
/* Its a good practice to prototype all functions including which are
* defined in header file itself such as inline functions before defining
* any function. This way, even if we use one function in another
* function, we do not have to worry about function undefined error
* possibilities.
*/
inline int absolute_number(int number);
inline int smaller_number(int a, int b);
inline int bigger_number(int a, int b);
inline int absolute_number(int number)
{
if (number < 0)
return -(number);
else
return number;
}
inline int smaller_number(int a, int b)
{
if (a > b)
return b;
else
return a;
}
inline int bigger_number(int a, int b)
{
if (a < b)
return b;
else
return a;
}
void string_to_vector(
std::string &a_string,
std::vector<std::string> &str_vector,
char delimeter = ',');
void pick_random_string(
std::string &str, const std::vector<std::string> &str_vector);
#endif