Skip to content

csUtility

Stephen P edited this page Oct 14, 2021 · 6 revisions

CoSprite's miscellaneous utility functions. Most will not see too much use, but if you are going to use them, they will prove helpful. As well, defines the standard CoSprite defines like the bool type, boolToString, and NULL (if these things are not already defined).

Functions

randInt

int randInt(int low, int high, bool inclusive)
Gives you a random integer from low to high. You can set whether or not bounds are inclusive or not.

digits

int digits(int num)
Given an integer, it returns out how many digits that integer takes up.

freeThisMem

void* freeThisMem(void* x)
Note: Nothing appears to be wrong with this function, but usage isn't advised. It just free()s your memory then returns NULL so you can do myMem = freeThisMem(myMem); one smooth line for free()ing, but at the same time you're old enough to set your own memory to NULL (or choose not to).

removeNewline

char* removeNewline(char* stuff, char replacement, int maxLength)
Replaces newline characters with replacement, spitting out a string of at most maxLength. Returns the same char* as inputted in stuff. Both your original string and the output will be the correct modified string.

getDistance

double getDistance(double x1, double y1, double x2, double y2)
Does the distance formula (Pythagorean Formula) calculation between two points.

Clone this wiki locally