Boink C Standard Library Reference
----------------------------------
<stdio.h>
void putchar(char c);
// Writes a single character to the standard output (screen).
// Params: c - character to print
void puts(const char* str);
// Writes a null-terminated string followed by a newline.
// Params: str - string to print
int input(char *buf, int len);
// Reads up to 'len' characters into 'buf' from user input.
// Blocks until Enter is pressed.
// Params: buf - buffer to store input
// len - max number of characters to read
void clear();
// Clears text on scren
char getchar();
// Reads a keypress
// Returns 1 character
<stdlib.h>
void exit(int status);
// Standard exit function
void sleep(int ms);
// Standard sleep function
<util.h>
char* itoa(int val, int base);
// Converts an integer to a string with the given base (e.g. base 10, base 16).
// Params: val - integer value to convert
// base - number base (between 2 and 16)
// Returns: pointer to static buffer with result (not thread-safe)
int strlen(const char *str);
// Returns the length of a null-terminated string (not including '\0').
// Params: str - input string
// Returns: number of characters
int strcmp(const char* s1, const char* s2);
// Compares two strings lexicographically.
// Returns: 0 if equal, negative if s1 < s2, positive if s1 > s2
int strncmp(const char* s1, const char* s2, int n);
// Like strcmp, but compares at most 'n' characters.
// Returns: same as strcmp
int atoi(const char* str);
// Converts a numeric string to an integer.
// Params: str - string representation of a number (e.g. "42")
// Returns: integer value
long strtol(const char *str, char **endptr, int base);
// Converts a string to a long, respecting base (e.g. base 10, 16).
// Params: str - input string
// endptr - out param: pointer to char after last parsed digit
// base - base to interpret number in
// Returns: converted long value
char* strtok(char* str, const char* delim);
// Tokenizes a string, splitting it into pieces using delimiters.
// Params: str - input string on first call, NULL on subsequent calls
// delim - characters to split on
// Returns: pointer to next token, or NULL when no more tokens
char* strchr(const char* str, int c);
// Finds the first occurrence of character c in string str.
// Params: str - input string
// c - character to find
// Returns: pointer to the character in str, or NULL if not found
char* strcat(char* dest, const char* src);
// Appends src to the end of dest (assumes dest is large enough).
// Params: dest - destination string (modified)
// src - source string
// Returns: pointer to dest
Sample Program
--------------
#include <stdio.h>
#include <stdlib.h>
#include <util.h>
int main(int argc, char** argv) {
clear(); // clear the screen
puts("hi from userland!\nargs:\n"); // print
puts("\n");
// loop pver arguments and print
for (int i = 0; i < argc; i++) {
puts(argv[i]);
puts("\n");
}
// classic first program -- input age, print age+10
puts("What is your age? ");
char buf[4];
input(buf, 4);
int age = atoi(buf);
puts("In 10 years you will be: ");
puts(itoa(age+10, 10));
putchar('\n');
// sleep 100 ticks (PIT is timed at 100Hz -- 100 ticks is 1s)
sleep(100);
putchar('\n');
// exit with status code
exit(0);
// crt0 ensures safe exit with code 0 IF not properly exited
// return 0 will trigger this functionality
return 0;
}