Programming I version 1.5.3
Programming I C Library
|
Base functions for Programming I Library. More...
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <stdbool.h>
#include "basedefs.h"
Go to the source code of this file.
Macros | |
#define | assert(description, condition) |
Checks the given condition. | |
#define | assert_code(x) x |
Allows writing code that is meant for use in an assertion. | |
#define | assert_not_null(pointer) |
Checks that the given pointer is not NULL. | |
#define | assert_x(description, condition, ...) |
Checks the given condition. | |
#define | count_if(init, has_more_steps, do_step, condition) |
Counts the number of iteration steps for which the given condition is true. | |
#define | ensure(description, condition) |
Checks the given postcondition. | |
#define | ensure_code(x) x |
Allows writing code that is meant for use in a postcondition. | |
#define | ensure_not_null(pointer) |
Checks that the given pointer is not NULL. | |
#define | ensure_x(description, condition, ...) |
Checks the given postcondition. | |
#define | EPSILON 0.00000001 |
A very small positive value. | |
#define | exists(i, length, condition) |
Checks whether the given condition is true for at least one step of an iteration. | |
#define | exists_x(init, has_more_steps, do_step, condition) |
Checks whether the given condition is true for at least one step of an iteration. | |
#define | exit base_exit |
Exits the process and returns the given status to the operating system. | |
#define | exit_if(condition, ...) |
Exits the program if the failure condition is true. | |
#define | forall(i, length, condition) |
Checks whether the given condition is true for all steps of an iteration. | |
#define | forall_x(init, has_more_steps, do_step, condition) |
Checks whether the given condition is true for all steps of an iteration. | |
#define | free base_free |
Frees memory blocks allocated with xmalloc or xcalloc. | |
#define | NO_ASSERT_DOC |
Switching assertion checking on and off. | |
#define | NO_ENSURE_DOC |
Switching assertion checking on and off. | |
#define | NO_REQUIRE_DOC |
Switching assertion checking on and off. | |
#define | panic(...) |
Exits the program. | |
#define | panic_if(condition, ...) |
Exits the program if the failure condition is true. | |
#define | PL printf("%s:%d\n", __func__, __LINE__) |
Print line number. | |
#define | PLf(...) |
Print line number and format string. | |
#define | PLi(i) printf("%s:%d: %d\n", __func__, __LINE__, i) |
Print line number and integer. | |
#define | require(description, condition) |
Checks the given precondition. | |
#define | require_not_null(argument) |
Checks that the given argument is not NULL. | |
#define | require_x(description, condition, ...) |
Checks the given precondition. | |
#define | test_equal_b(a, e) base_test_equal_b(__FILE__, __LINE__, a, e) |
Checks whether the actual boolean (first argument) is equal to the expected boolean (second argument). | |
#define | test_equal_boa(a, e, ne) base_test_equal_ba(__FILE__, __LINE__, a, e, ne) |
Checks whether the actual array (first argument) is equal to the expected array (second argument). | |
#define | test_equal_c(a, e) base_test_equal_c(__FILE__, __LINE__, a, e) |
Checks whether the actual character (first argument) is equal to the expected character (second argument). | |
#define | test_equal_ca(a, e, ne) base_test_equal_ca(__FILE__, __LINE__, a, e, ne) |
Checks whether the actual array (first argument) is equal to the expected array (second argument). | |
#define | test_equal_i(a, e) base_test_equal_i(__FILE__, __LINE__, a, e) |
Checks whether the actual int (first argument) is equal to the expected int (second argument). | |
#define | test_equal_s(a, e) base_test_equal_s(__FILE__, __LINE__, a, e) |
Checks whether the actual String (first argument) is equal to the expected String (second argument). | |
#define | test_equal_struct(a, e, p) base_test_equal_struct(__FILE__, __LINE__, a, e, p) |
Checks whether the actual struct (first argument) is equal to the expected struct (second argument). | |
#define | test_within_d(a, e, epsilon) base_test_within_d(__FILE__, __LINE__, a, e, epsilon) |
Checks whether the actual double (first argument) is within +/-epsilon (third argument) of the expected double (second argument). | |
#define | test_within_i(a, e, epsilon) base_test_within_i(__FILE__, __LINE__, a, e, epsilon) |
Checks whether the actual int (first argument) is within +/-epsilon (third argument) of the expected int (second argument). | |
#define | xcalloc(num, size) base_calloc(__FILE__, __func__, __LINE__, num, size) |
Allocates a block of (num * size) bytes with calloc . | |
#define | xmalloc(size) base_malloc(__FILE__, __func__, __LINE__, size) |
Allocates a block of size bytes with xmalloc. | |
#define | xrealloc(ptr, size) base_realloc(__FILE__, __func__, __LINE__, ptr, size) |
Reallocates a block of size bytes using realloc . | |
Functions | |
bool | b_rnd (void) |
Returns a random Boolean between (true or false) with 50% probability. | |
bool | base_test_equal_b (const char *file, int line, bool a, bool e) |
Checks whether the actual value a is equal to the expected value e . | |
bool | base_test_equal_c (const char *file, int line, char a, char e) |
Checks whether the actual value a is equal to the expected value e . | |
bool | base_test_equal_i (const char *file, int line, int a, int e) |
Checks whether the actual value a is equal to the expected value e . | |
bool | base_test_equal_s (const char *file, int line, String a, String e) |
Checks whether the actual value a is equal to the expected value e . | |
bool | base_test_equal_struct (const char *file, int line, Any a, Any e, AnyFn predicate) |
Checks whether the members of struct a are equal to the members of struct e . | |
bool | base_test_within_d (const char *file, int line, double a, double e, double epsilon) |
Checks whether the actual value a is within +/-epsilon of the expected value e . | |
bool | base_test_within_i (const char *file, int line, int a, int e, int epsilon) |
Checks whether the actual value a is within +/-epsilon of the expected value e . | |
double | d_input (void) |
Reads a double from standard input. | |
double | d_of_s (String s) |
Converts a String to a double. | |
double | d_rnd (double i) |
Returns a random double between in the interval [0,i). | |
void | get_line (char *line, int n) |
Reads at most n-1 characters into an existing buffer. | |
int | i_input (void) |
Reads an integer from standard input. | |
int | i_of_s (String s) |
Converts a String to an integer. | |
int | i_rnd (int i) |
Returns a random int between in the interval [0,i). | |
void | printb (bool b) |
Prints a boolean value. | |
void | printba (Byte *a, int n) |
Prints a C-array of n Bytes. | |
void | printbaln (Byte *a, int n) |
Prints a C-array of n Bytes followed by a line break. | |
void | printbln (bool b) |
Prints a boolean value followed by a line break. | |
void | printboa (bool *a, int n) |
Prints a C-array of n booleans. | |
void | printboaln (bool *a, int n) |
Prints a C-array of n booleans followed by a line break. | |
void | printc (char c) |
Prints a character. | |
void | printca (char *a, int n) |
Prints a C-array of n characters. | |
void | printcaln (char *a, int n) |
Prints a C-array of n characters followed by a line break. | |
void | printcln (char c) |
Prints a character followed by a line break. | |
void | printd (double d) |
Prints a double. | |
void | printda (double *a, int n) |
Prints a C-array of n doubles. | |
void | printdaln (double *a, int n) |
Prints a C-array of n doubles followed by a line break. | |
void | printdln (double d) |
Prints a double followed by a line break. | |
void | printi (int i) |
Prints an integer. | |
void | printia (int *a, int n) |
Prints a C-array of n integers. | |
void | printialn (int *a, int n) |
Prints a C-array of n integers followed by a line break. | |
void | printiln (int i) |
Prints an integer followed by a line break. | |
void | println () |
Prints a line break. | |
void | prints (String s) |
Prints a String. | |
void | printsa (String *a, int n) |
Prints a C-array of n Strings. | |
void | printsaln (String *a, int n) |
Prints a C-array of n Strings followed by a line break. | |
void | printsln (String s) |
Prints a String followed by a line break. | |
void | report_memory_leaks (bool do_check) |
Switches memory checking on or off. | |
bool | s_contains (String s, String part) |
Returns true iff s contains part. | |
String | s_copy (String s) |
Creates a copy of the given string. | |
bool | s_equals (String s, String t) |
Returns true iff s and t are equal. | |
char | s_get (String s, int i) |
Returns character at index i . | |
String | s_input (int n) |
Reads at most n-1 characters into a newly allocated string. | |
int | s_length (String s) |
Returns the length of the string (number of characters). | |
String | s_read_file (String name) |
Reads the contents of a file into a String. | |
void | s_set (String s, int i, char c) |
Sets s element at index i to value v. | |
void | s_write_file (String name, String data) |
Writes a String to a file. | |
void | write_file_data (String name, Byte *data, int n) |
Writes a memory block to a file. | |
Base functions for Programming I Library.
Here you find basic functions for output, input, files, random numbers, dynamic memory allocation, timing, assertions, and testing.
Types names are written in upper camel case, such as String
, except for predefined type names such as int
, double
, and bool
. This library does not cover type float
. This library does not deal with unsigned
types.
Function names are written in lower case. Parts within function names are separated with an underscore character, such as in base_init
. This makes function names distinguishable from type names.
Constants, such as NULL
, are written in upper case. This is independent of whether they have been defined as C constants or with preprocessor define
statements.
The type String
is simply defined as a pointer to a character:
There are several type declarations for functions. Example:
The type IntStringToString
represents a pointer to a function that takes an integer and a String and returns a String.
Memory is allocated using xmalloc or xcalloc and released with free. These functions (in fact: macros) keep track of allocated memory and report memory leaks. Make sure to always use xmalloc or xcalloc rather than malloc
and calloc
in your code.
Output:
Let example.txt
be
To read this file:
Output:
See test functions in .c file for more examples.
#define assert | ( | description, | |
condition | |||
) |
Checks the given condition.
If the condition is true, does nothing. If the condition is false, reports the file and line of the assertion and stops the program. Assertions are conditions that have to be valid at a particular point. If an assertion is false this indicates a bug in the program.
Example use of an assertion:
Example output of failed assertions:
myfile.c, line 12: assertion "not too large" (x < 3) violated myfile.c, line 12: assertion "sorted" (forall(int i = 0, i < n-1, i++, a[i] <= a[i+1])) violated
[in] | description | String a description of the condition that has to be valid |
[in] | condition | boolean the condition to check |
#define assert_code | ( | x | ) | x |
Allows writing code that is meant for use in an assertion.
The code is removed if NO_ASSERT is defined.
Example:
#define assert_not_null | ( | pointer | ) |
Checks that the given pointer is not NULL.
If so, does nothing. Otherwise reports the location of the assertion and stops the program. Assertions are conditions that have to be valid at a particular point. If an assertion is false this indicates a bug in the program.
Example use of an assertion:
Example output of failed assertion:
myfile.c, line 12: assertion "not null" (s) violated
[in] | pointer | a pointer that must not be null |
#define assert_x | ( | description, | |
condition, | |||
... | |||
) |
Checks the given condition.
If the condition is true, does nothing. If the condition is false, reports the file and line of the assertion and stops the program. Assertions are conditions that have to be valid at a particular point. If an assertion is false this indicates a bug in the program.
Example use of an assertion:
Example output of failed assertions:
myfile.c, line 12: assertion "not too large" violated: x == 3 myfile.c, line 12: assertion "sorted" violated: a[2] == 5 && a[3] == 4
[in] | description | String a description of the condition that has to be valid |
[in] | condition | boolean the condition to check |
#define count_if | ( | init, | |
has_more_steps, | |||
do_step, | |||
condition | |||
) |
Counts the number of iteration steps for which the given condition is true.
Primarily for use in assertions, preconditions, and postconditions.
[in] | init | initialization expression |
[in] | has_more_steps | boolean expression for continuing the iteration |
[in] | do_step | advance the iteration state |
[in] | condition | boolean expression |
Example: Count the number of non-zero array elements:
#define ensure | ( | description, | |
condition | |||
) |
Checks the given postcondition.
If the condition is true, does nothing. If the condition is false, reports the location of the postcondition and stops the program. A postcondition is a special type of assertion that has to be valid before returning from a function.
Example use of a postcondition:
Example output of failed postconditions:
myfile.c, line 12: myfunction's postcondition "not negative" (result >= 0) violated myfile.c, line 12: myfunction's postcondition "sorted" (forall(int i = 0, i < n-1, i++, a[i] <= a[i+1])) violated
[in] | description | String a description of the condition that has to be valid |
[in] | condition | boolean the condition to check |
#define ensure_code | ( | x | ) | x |
Allows writing code that is meant for use in a postcondition.
The code is removed if NO_ENSURE is defined.
Example:
#define ensure_not_null | ( | pointer | ) |
Checks that the given pointer is not NULL.
If so, does nothing. Otherwise reports the location of the postcondition and stops the program. A postcondition is a special type of assertion that has to be valid before returning from a function.
Example use of a postcondition:
Example output of failed postcondition:
myfile.c, line 12: myfunction's postcondition "not null" (s) violated
[in] | pointer | a pointer that must not be null |
#define ensure_x | ( | description, | |
condition, | |||
... | |||
) |
Checks the given postcondition.
If the condition is true, does nothing. If the condition is false, reports the location of the postcondition and stops the program. A postcondition is a special type of assertion that has to be valid before returning from a function.
Example use of a postcondition:
Example output of failed postconditions:
myfile.c, line 12: myfunction's postcondition "not negative" (result >= 0) violated myfile.c, line 12: myfunction's postcondition "sorted" violated: a[2] == 5 && a[3] == 4
[in] | description | String a description of the condition that has to be valid |
[in] | condition | boolean the condition to check |
#define EPSILON 0.00000001 |
A very small positive value.
#define exists | ( | i, | |
length, | |||
condition | |||
) |
Checks whether the given condition is true for at least one step of an iteration.
Primarily for use in assertions, preconditions, and postconditions.
[in] | i | name of iteration variable |
[in] | length | number of iteration steps, i in [0, length) |
[in] | condition | boolean expression to check for each iteration step |
Example: Checking whether an array contains negative elements:
#define exists_x | ( | init, | |
has_more_steps, | |||
do_step, | |||
condition | |||
) |
Checks whether the given condition is true for at least one step of an iteration.
Primarily for use in assertions, preconditions, and postconditions.
[in] | init | initialization expression |
[in] | has_more_steps | boolean expression for continuing the iteration |
[in] | do_step | advance the iteration state |
[in] | condition | boolean expression to check for each iteration step |
Example: Checking whether an array contains negative elements:
#define exit base_exit |
Exits the process and returns the given status to the operating system.
[in] | status | (int) exit status of the process |
#define exit_if | ( | condition, | |
... | |||
) |
Exits the program if the failure condition is true.
The further arguments contain the reason for exiting the program, using a format string.
#define forall | ( | i, | |
length, | |||
condition | |||
) |
Checks whether the given condition is true for all steps of an iteration.
Primarily for use in assertions, preconditions, and postconditions.
[in] | i | name of iteration variable |
[in] | length | number of iteration steps, i in [0, length) |
[in] | condition | boolean expression to check for each iteration step |
Example: Checking whether an array is sorted:
#define forall_x | ( | init, | |
has_more_steps, | |||
do_step, | |||
condition | |||
) |
Checks whether the given condition is true for all steps of an iteration.
Primarily for use in assertions, preconditions, and postconditions.
[in] | init | initialization expression |
[in] | has_more_steps | boolean expression for continuing the iteration |
[in] | do_step | advance the iteration state |
[in] | condition | boolean expression to check for each iteration step |
Example: Checking whether an array is sorted:
#define free base_free |
#define NO_ASSERT_DOC |
Switching assertion checking on and off.
If NO_ASSERT
is defined, then assertions will not be compiled.
#define NO_ENSURE_DOC |
Switching assertion checking on and off.
If NO_ENSURE
is defined, then postconditions will not be compiled.
#define NO_REQUIRE_DOC |
Switching assertion checking on and off.
If NO_REQUIRE
is defined, then preconditions will not be compiled.
#define panic | ( | ... | ) |
Exits the program.
The arguments contain the reason for the panic, using a format string. Reports the line number and the reason for the failure.
#define panic_if | ( | condition, | |
... | |||
) |
Exits the program if the failure condition is true.
The further arguments contain the reason for the panic, using a format string. Reports the line number and the reason for the failure.
#define PL printf("%s:%d\n", __func__, __LINE__) |
Print line number.
Example: PL;
#define PLf | ( | ... | ) |
Print line number and format string.
Example: PLf("i = %d", 123);
#define PLi | ( | i | ) | printf("%s:%d: %d\n", __func__, __LINE__, i) |
Print line number and integer.
Example: PL(1);
#define require | ( | description, | |
condition | |||
) |
Checks the given precondition.
If the condition is true, does nothing. If the condition is false, reports the location of the precondition and stops the program. A precondition is a special type of assertion that has to be valid at the beginning of a function.
Example use of a precondition:
Example output of failed preconditions:
myfile.c, line 12: myfunction's precondition "not too large" (x < 3) violated myfile.c, line 12: myfunction's precondition "sorted" (forall(int i = 0, i < n-1, i++, a[i] <= a[i+1])) violated
[in] | description | String a description of the condition that has to be valid |
[in] | condition | boolean the condition to check |
#define require_not_null | ( | argument | ) |
Checks that the given argument is not NULL.
If so, does nothing. Otherwise reports the location of the precondition and stops the program. A precondition is a special type of assertion that has to be valid at the beginning of a function.
Example use of a precondition:
Example output of failed preconditions:
myfile.c, line 12: myfunction's precondition "not null" (s) violated
[in] | argument | pointer a pointer that must not be null |
#define require_x | ( | description, | |
condition, | |||
... | |||
) |
Checks the given precondition.
If the condition is true, does nothing. If the condition is false, reports the location of the precondition and stops the program. A precondition is a special type of assertion that has to be valid at the beginning of a function.
Example use of a precondition:
Example output of failed preconditions:
myfile.c, line 12: myfunction's precondition "not too large" violated: x == 3 myfile.c, line 12: myfunction's precondition "sorted" violated: a[2] == 5 && a[3] == 4
[in] | description | String a description of the condition that has to be valid |
[in] | condition | boolean the condition to check |
#define test_equal_b | ( | a, | |
e | |||
) | base_test_equal_b(__FILE__, __LINE__, a, e) |
Checks whether the actual boolean (first argument) is equal to the expected boolean (second argument).
#define test_equal_boa | ( | a, | |
e, | |||
ne | |||
) | base_test_equal_ba(__FILE__, __LINE__, a, e, ne) |
Checks whether the actual array (first argument) is equal to the expected array (second argument).
#define test_equal_c | ( | a, | |
e | |||
) | base_test_equal_c(__FILE__, __LINE__, a, e) |
Checks whether the actual character (first argument) is equal to the expected character (second argument).
#define test_equal_ca | ( | a, | |
e, | |||
ne | |||
) | base_test_equal_ca(__FILE__, __LINE__, a, e, ne) |
Checks whether the actual array (first argument) is equal to the expected array (second argument).
#define test_equal_i | ( | a, | |
e | |||
) | base_test_equal_i(__FILE__, __LINE__, a, e) |
Checks whether the actual int (first argument) is equal to the expected int (second argument).
#define test_equal_s | ( | a, | |
e | |||
) | base_test_equal_s(__FILE__, __LINE__, a, e) |
Checks whether the actual String (first argument) is equal to the expected String (second argument).
#define test_equal_struct | ( | a, | |
e, | |||
p | |||
) | base_test_equal_struct(__FILE__, __LINE__, a, e, p) |
Checks whether the actual struct (first argument) is equal to the expected struct (second argument).
#define test_within_d | ( | a, | |
e, | |||
epsilon | |||
) | base_test_within_d(__FILE__, __LINE__, a, e, epsilon) |
Checks whether the actual double (first argument) is within +/-epsilon (third argument) of the expected double (second argument).
#define test_within_i | ( | a, | |
e, | |||
epsilon | |||
) | base_test_within_i(__FILE__, __LINE__, a, e, epsilon) |
Checks whether the actual int (first argument) is within +/-epsilon (third argument) of the expected int (second argument).
#define xcalloc | ( | num, | |
size | |||
) | base_calloc(__FILE__, __func__, __LINE__, num, size) |
Allocates a block of (num * size) bytes with calloc
.
Exits with error message on failure. The allocated bytes are set to zero (the initial c
in calloc
stands for clear).
[in] | num | number of elements |
[in] | size | size (in bytes) of each element |
#define xmalloc | ( | size | ) | base_malloc(__FILE__, __func__, __LINE__, size) |
Allocates a block of size bytes with xmalloc.
Exits with an error message on failure. The contents of the allocated memory block is not initialized (i.e., the memory block contains arbitrary values).
[in] | size | number of bytes to allocate |
#define xrealloc | ( | ptr, | |
size | |||
) | base_realloc(__FILE__, __func__, __LINE__, ptr, size) |
Reallocates a block of size bytes using realloc
.
Exits with error message on failure. The contents of the allocated memory block is not initialized (i.e., the memory block contains arbitrary values).
[in] | ptr | pointer to reallocate |
[in] | size | number of bytes to allocate |
bool b_rnd | ( | void | ) |
Returns a random Boolean between (true or false) with 50% probability.
bool base_test_equal_b | ( | const char * | file, |
int | line, | ||
bool | a, | ||
bool | e | ||
) |
Checks whether the actual value a
is equal to the expected value e
.
bool base_test_equal_c | ( | const char * | file, |
int | line, | ||
char | a, | ||
char | e | ||
) |
Checks whether the actual value a
is equal to the expected value e
.
bool base_test_equal_i | ( | const char * | file, |
int | line, | ||
int | a, | ||
int | e | ||
) |
Checks whether the actual value a
is equal to the expected value e
.
Checks whether the actual value a
is equal to the expected value e
.
Checks whether the members of struct a
are equal to the members of struct e
.
Uses the given predicate
function to perform the comparison.
bool base_test_within_d | ( | const char * | file, |
int | line, | ||
double | a, | ||
double | e, | ||
double | epsilon | ||
) |
Checks whether the actual value a
is within +/-epsilon of the expected value e
.
bool base_test_within_i | ( | const char * | file, |
int | line, | ||
int | a, | ||
int | e, | ||
int | epsilon | ||
) |
Checks whether the actual value a
is within +/-epsilon of the expected value e
.
double d_input | ( | void | ) |
Reads a double from standard input.
The input has to be terminated by a line break.
double d_of_s | ( | String | s | ) |
Converts a String to a double.
double d_rnd | ( | double | i | ) |
Returns a random double between in the interval [0,i).
0 is inclusive, i is exclusive.
[in] | i | upper boundary (exclusive) |
void get_line | ( | char * | line, |
int | n | ||
) |
Reads at most n-1 characters into an existing buffer.
Stops reading if newline or end-of-file have been reached. Does not return the newline character.
[in,out] | line | buffer to write into (size of buffer at least n bytes), whill be a zero-terminated String |
[in] | n | maximum number of bytes to read, has to be at least 8 |
int i_input | ( | void | ) |
Reads an integer from standard input.
The input has to be terminated by a line break.
int i_of_s | ( | String | s | ) |
Converts a String to an integer.
int i_rnd | ( | int | i | ) |
Returns a random int between in the interval [0,i).
0 is inclusive, i is exclusive.
[in] | i | upper boundary (exclusive) |
void printb | ( | bool | b | ) |
Prints a boolean value.
void printba | ( | Byte * | a, |
int | n | ||
) |
Prints a C-array of n Bytes.
void printbaln | ( | Byte * | a, |
int | n | ||
) |
Prints a C-array of n Bytes followed by a line break.
void printbln | ( | bool | b | ) |
Prints a boolean value followed by a line break.
void printboa | ( | bool * | a, |
int | n | ||
) |
Prints a C-array of n booleans.
void printboaln | ( | bool * | a, |
int | n | ||
) |
Prints a C-array of n booleans followed by a line break.
void printc | ( | char | c | ) |
Prints a character.
void printca | ( | char * | a, |
int | n | ||
) |
Prints a C-array of n characters.
void printcaln | ( | char * | a, |
int | n | ||
) |
Prints a C-array of n characters followed by a line break.
void printcln | ( | char | c | ) |
Prints a character followed by a line break.
void printd | ( | double | d | ) |
Prints a double.
void printda | ( | double * | a, |
int | n | ||
) |
Prints a C-array of n doubles.
void printdaln | ( | double * | a, |
int | n | ||
) |
Prints a C-array of n doubles followed by a line break.
void printdln | ( | double | d | ) |
Prints a double followed by a line break.
void printi | ( | int | i | ) |
Prints an integer.
void printia | ( | int * | a, |
int | n | ||
) |
Prints a C-array of n integers.
void printialn | ( | int * | a, |
int | n | ||
) |
Prints a C-array of n integers followed by a line break.
void printiln | ( | int | i | ) |
Prints an integer followed by a line break.
void println | ( | ) |
Prints a line break.
void prints | ( | String | s | ) |
Prints a String.
void printsa | ( | String * | a, |
int | n | ||
) |
Prints a C-array of n Strings.
void printsaln | ( | String * | a, |
int | n | ||
) |
Prints a C-array of n Strings followed by a line break.
void printsln | ( | String | s | ) |
Prints a String followed by a line break.
void report_memory_leaks | ( | bool | do_check | ) |
Switches memory checking on or off.
If on, checks for memory leaks when thr program terminates.
[in] | do_check | if true , then memory is checked |
Returns true iff s
contains part.
[in] | s | input string |
[in] | part | input string |
Creates a copy of the given string.
Memory of copy is dynamically allocated.
[in] | s | input string |
Returns true iff s
and t
are equal.
[in] | s | input string |
[in] | t | input string |
s
and t
are equal char s_get | ( | String | s, |
int | i | ||
) |
Returns character at index i
.
[in] | s | input string |
[in] | i | index of character to return |
String s_input | ( | int | n | ) |
Reads at most n-1 characters into a newly allocated string.
Stops reading if newline or end-of-file is reached. Does not return the newline character.
[in] | n | maximum number of bytes to read, has to be at least 8 |
int s_length | ( | String | s | ) |
Returns the length of the string (number of characters).
[in] | s | input string |
Reads the contents of a file into a String.
The function fails if the file does not exist or cannot be read.
[in] | name | file name (including path) |
void s_set | ( | String | s, |
int | i, | ||
char | c | ||
) |
Sets s element at index i to value v.
[in,out] | s | input string |
[in] | i | index of character to set |
[in] | c | character to set |
Writes a String to a file.
An existing file of the same name will be overwritten.
[in] | name | file name (including path) |
[in] | data | the data to write to the file |
Writes a memory block to a file.
An existing file of the same name will be overwritten.
[in] | name | file name (including path) |
[in] | data | the data to write to the file |
[in] | n | the number of bytes to write to the file |