Summary

August 29, 2017 ยท View on GitHub

MembersDescriptions
void init_chain(Chain * chain)Construct chain
void clear_chain(Chain * chain)Clear chain
void append_cstr_to_chain(Chain * chain,const char * text)Append a cstring to a chain
void append_flink_to_chain(Chain * chain,Fraction fraction)Append fraction as single Link to chain
void append_fraction_to_chain(Chain * chain,Fraction fraction)Append fraction as string to chain
void append_chain_to_chain(Chain * chain1,Chain chain2)Append the contents in one chain to another
void append_stream_to_chain(Chain * chain,FILE * stream)Append the contents of a stream to a chain
void clear_stream(FILE * stream)Erase stream contents
void append_chain_to_stream(Chain chain,FILE * stream)Append chain to stream
void chain_to_stream(Chain chain,FILE * stream)Assign chain to stream
int chain_to_cstr(Chain chain,char * buffer)Convert chain to cstring
void write_chain_to_file(Chain chain,Chain filename)Set file contents to chain's contents
void read_file_to_chain(Chain * chain,Chain filename)Set chain contents to file's contents
int compare_chains(Chain a,Chain b)Compare chains
``Fraction chain_to_fraction(Chain chain)Convert chain to fraction
``Fraction get_next_byte_of_stream(FILE * file)
void runtime_error(const char * msg,...)Show error message and exit
``Fraction construct_fraction(FractionInt num,FractionInt den)Construct Fraction
void reduce_fraction(Fraction * a)Reduce fraction to most basic form
``Fraction add_fractions(Fraction a,Fraction b)Add two fractions
``Fraction subtract_fractions(Fraction a,Fraction b)Subtract two fractions
``Fraction multiply_fractions(Fraction a,Fraction b)Multiply two fractions
``Fraction divide_fractions(Fraction a,Fraction b)Divide two fractions
``Fraction modulus_fractions(Fraction a,Fraction b)Modulus fractions
``Fraction factorial_fraction(Fraction a)Get factorial of fraction
int compare_fractions(Fraction a,Fraction b)Compare fractions
``Fraction pow_fractions(Fraction a,Fraction b)Exponentiate fractions
struct Chain
struct Fraction
struct Link

Members

void init_chain(Chain * chain)

Construct chain

Set defaults for chain: length to 0 and start to NULL

Parameters

  • chain The chain being constructed

void clear_chain(Chain * chain)

Clear chain

Free all links in chain and set start to NULL

Parameters

  • chain The chain being cleared

void append_cstr_to_chain(Chain * chain,const char * text)

Append a cstring to a chain

Append each character of the cstring as a Link to the chain.

Parameters

  • chain The chain being modified

  • text The string being added to the chain

Append fraction as single Link to chain

Parameters

  • chain The chain being modified

  • fraction The fraction being added to the chain

void append_fraction_to_chain(Chain * chain,Fraction fraction)

Append fraction as string to chain

Fraction is first converted into a string format. For example, 25/1 would be converted to "twenty five" and then appended to the chain

Parameters

  • chain The chain being modified

  • fraction The fraction being added to the chain

void append_chain_to_chain(Chain * chain1,Chain chain2)

Append the contents in one chain to another

Parameters

  • chain1 The chain being modified

  • chain2 The chain being appended to chain1

void append_stream_to_chain(Chain * chain,FILE * stream)

Append the contents of a stream to a chain

Each char is read from the stream and copied to the chain as a fraction/Link.

Parameters

  • chain The chain being modified

  • stream The stream whose contents are read

void clear_stream(FILE * stream)

Erase stream contents

Parameters

  • stream The stream being cleared

void append_chain_to_stream(Chain chain,FILE * stream)

Append chain to stream

Print each fraction of chain to the stream to be appended as a char

Parameters

  • chain The chain being read

  • stream The stream being appended to

void chain_to_stream(Chain chain,FILE * stream)

Assign chain to stream

Clear the stream, then call append_chain_to_stream

Parameters

  • chain The chain being read

  • stream The stream being copied to

int chain_to_cstr(Chain chain,char * buffer)

Convert chain to cstring

Print each fraction of chain to the cstring buffer to be appended as a char This function is not safe. If buffer is too small to hold the contents of chain, a segfault will occur

Parameters

  • chain The chain being read

  • buffer The cstring being appended to

Returns

The length of the buffer.

void write_chain_to_file(Chain chain,Chain filename)

Set file contents to chain's contents

Open a file and set its contents to that of the chain's. As with other functions, each fraction is converted to a char. An error will be thrown upon any problem opening the file

Parameters

  • chain The chain being read

  • filename A chain holding the filename of the file we're opening

void read_file_to_chain(Chain * chain,Chain filename)

Set chain contents to file's contents

Open a file and read its contents to the chain's, replacing any previous values(an assign, not append). As with other functions, each char is converted to a fraction. An error will be thrown upon any problem opening the file

Parameters

  • chain The chain being overwritten

  • filename A chain holding the filename of the file we're opening

int compare_chains(Chain a,Chain b)

Compare chains

Check if chains are equivalent. Will return 0 if they are, and another value if they are not.

Parameters

  • a The first chain

  • b The second chain

Returns

The comparison value

``Fraction chain_to_fraction(Chain chain)

Convert chain to fraction

Parse chain to convert to a fraction value. Return 0/1 if chain is invalid.

Parameters

  • chain The chain being parsed

Returns

The fraction value of the chain

``Fraction get_next_byte_of_stream(FILE * file)

void runtime_error(const char * msg,...)

Show error message and exit

Shows an error in the style of fprintf in red text, then exit with EXIT_FAILURE

Parameters

  • msg The fprintf-style format string

  • ... Any values referenced by the format string

``Fraction construct_fraction(FractionInt num,FractionInt den)

Construct Fraction

Parameters

  • num The numerator

  • den The denominator

Returns

The fraction constructed

void reduce_fraction(Fraction * a)

Reduce fraction to most basic form

Parameters

  • a The fraction to be reduced

``Fraction add_fractions(Fraction a,Fraction b)

Add two fractions

Parameters

  • a The first fraction

  • b The second fraction

Returns

a+b

``Fraction subtract_fractions(Fraction a,Fraction b)

Subtract two fractions

Parameters

  • a The first fraction

  • b The second fraction

Returns

a-b

``Fraction multiply_fractions(Fraction a,Fraction b)

Multiply two fractions

Parameters

  • a The first fraction

  • b The second fraction

Returns

a*b

``Fraction divide_fractions(Fraction a,Fraction b)

Divide two fractions

Parameters

  • a The first fraction

  • b The second fraction

Returns

a/b

``Fraction modulus_fractions(Fraction a,Fraction b)

Modulus fractions

Get remainder after dividing two fractions. Throw an error if the fractions are non-integers

Parameters

  • a The first fraction

  • b The second fraction

Returns

ab

``Fraction factorial_fraction(Fraction a)

Get factorial of fraction

Return the factorial of a fraction. Throw an error if the fractions are non-integers

Parameters

  • a The fraction to be factorialized

Returns

a!

int compare_fractions(Fraction a,Fraction b)

Compare fractions

Return 0 if fractions are equal, -1 if a<b, and 1 if a>b

Parameters

  • a The first fraction

  • b The second fraction

Returns

The comparison result

``Fraction pow_fractions(Fraction a,Fraction b)

Exponentiate fractions

Return a to the bth power. This uses floating point math, so the answer will not be exact. Invalid arguments will throw an error.

Parameters

  • a The first fraction

  • b The second fraction

Returns

a^b

struct Chain

Summary

MembersDescriptions
ChainLengthInt length
``Link*start
``Link*end

Members

ChainLengthInt length

``Link*start

``Link*end

struct Fraction

Summary

MembersDescriptions
FractionInt num
FractionInt den

Members

FractionInt num

FractionInt den

struct Link

Summary

MembersDescriptions
``Fraction value
struct Link*prev
struct Link*next

Members

``Fraction value

struct Link*prev

struct Link*next

Generated by Moxygen