C Standard Library Functions
This is a list of function prototypes in the standard C library in alphabetical order and a list of prototypes grouped by functionality.
Alphabetical List
Buffer Manipulation
Character Classification and Conversion
Data Conversion
Directory Manipulation
File Manipulation
Stream I/O
Low level I/O
Mathematics
Memory Allocation
Process Control
Searching and Sorting
String Manipulation
Time
Description
The Comments column contains a very brief description of the use of the function. The list is not complete, however it provides information on the major functions in the C Runtime Library. It should, at the very least, indicate what functions are available in the standard C library allow you to do more investigation on your own. Some of the C library functions documented elsewhere may not be available in FreeBASIC. Check the appropriate include file for more information.
Note: The following prototypes are not the official FreeBASIC prototypes (see the include files), however, they will give you enough information to properly use the functions.
The Include File column contains the name of the file which you must include, using the `#include` directive at the beginning of your program. If you don't include the appropriate include file, the program either will not compile, or it will compile apparently correctly but give incorrect results when run. All of the C Runtime headers are located in the `crt` directory; for example, if the specified header is `math.bi`, use `include "crt/math.bi"` or `include "crt\math.bi"`, our just `include "crt.bi"` including all the others.
The Prototype column contains the following information:

- The name of the function;
- The parameters required for the function in parenthesis, together with the data-type of the parameters;
- The data-type of the value returned by the function.

For example `atoi(a as zstring ptr) as integer` means that the function `atoi` returns a value of type integer and requires a character zstring ptr as its argument.
Alphabetical List

Buffer Manipulation
`#include "crt/string.bi"`

Prototype (with parameters) | Comments
memchr(s as any ptr, c as integer, n as size_t) as any ptr | Search for a character in a buffer.
memcmp(s1 as any ptr, s2 as any ptr, n as size_t) as integer | Compare two buffers.
memcpy(dest as any ptr, src as any ptr, n as size_t) as any ptr | Copy one buffer into another .
memmove(dest as any ptr, src as any ptr, n as size_t) as any ptr | Move a number of bytes from one buffer lo another.
memset(s as any ptr, c as integer, n as size_t) as any ptr | Set all bytes of a buffer to a given character.

Character Classification and Conversion
`#include "crt/ctype.bi"`

Prototype (with parameters) | Comments
isalnum(c as integer) as integer | True if c is alphanumeric.
isalpha(c as integer) as integer | True if c is a letter.
isascii(c as integer) as integer | True if c is ASCII .
iscntrl(c as integer) as integer | True if c is a control character.
isdigit(c as integer) as integer | True if c is a decimal digit.
isgraph(c as integer) as integer | True if c is a graphical character.
islower(c as integer) as integer | True if c is a lowercase letter.
isprint(c as integer) as integer | True if c is a printable character.
ispunct(c as integer) as integer | True if c is a punctuation character.
isspace(c as integer) as integer | True if c is a space character.
isupper(c as integer) as integer | True if c is an uppercase letter.
isxdigit(c as integer) as integer | True if c is a hexadecimal digit.
toascii(c as integer) as integer | Convert c to ASCII .
tolower(c as integer) as integer | Convert c to lowercase.
toupper(c as integer) as integer | Convert c to uppercase.

Data Conversion
`#include "crt/stdlib.bi"`

Prototype (with parameters) | Comments
atof(string1 as zstring ptr) as double | Convert zstring to floating point value.
atoi(string1 as zstring ptr) as integer | Convert zstring to an integer value.
atol(string1 as zstring ptr) as integer | Convert zstring to a long integer value.
itoa(value as integer, zstring as zstring ptr, radix as integer) as zstring ptr | Convert an integer value to a zstring using given radix.
ltoa(value as long, zstring as zstring ptr, radix as integer) as zstring ptr | Convert long integer to zstring in a given radix.
strtod(string1 as zstring ptr, endptr as zstring ptr) as double | Convert zstring to a floating point value.
strtol(string1 as zstring ptr, endptr as zstring ptr, radix as integer) as long | Convert zstring to a long integer using a given radix.
strtoul(string1 as zstring ptr, endptr as zstring ptr, radix as integer) as ulong | Convert zstring to unsigned long.

Directory Manipulation
`#include "crt/io.bi"`

Prototype (with parameters) | Comments
_chdir(path as zstring ptr) as integer | Change current directory to given path.
_getcwd(path as zstring ptr, numchars as integer) as zstring ptr | Returns name of current working directory.
_mkdir(path as zstring ptr) as integer | Create a directory using given path name.
_rmdir(path as zstring ptr) as integer | Delete a specified directory.

File Manipulation
`#include "crt/sys/stat.bi"`
`#include "crt/io.bi"`

Prototype (with parameters) | Comments
chmod(path as zstring ptr, pmode as integer) as integer | Change permission settings of a file.
fstat(handle as integer, buffer as type stat ptr) as integer | Get file status information.
remove(path as zstring ptr) as integer | Delete a named file.
rename_(oldname as zstring ptr, newname as zstring ptr) as integer | rename a file.
stat(path as zstring ptr, buffer as type stat ptr) as integer | Get file status information of named file.
umask(pmode as uinteger) as uinteger | Set file permission mask.

Stream I/O
`#include "crt/stdio.bi"`

Prototype (with parameters) | Comments
clearerr(file_pointer as FILE ptr) | Clear error indicator of stream,
fclose(file_pointer as FILE ptr) as integer | Close a file,
feof(file_pointer as FILE ptr) as integer | Check if end of file occurred on a stream.
ferror(file_pointer as FILE ptr) as integer | Check if any error occurred during file I/0.
fflush(file_pointer as FILE ptr) as integer | Write out (flush) buffer to file.
fgetc(file_pointer as FILE ptr) as integer | Get a character from a stream.
fgetpos(file_pointer as FILE ptr, fpos_t current_pos) as integer | Get the current position in a stream.
fgets(string1 as zstring ptr, maxchar as integer, file_pointer as FILE ptr) as zstring ptr | Read a zstring from a file.
fopen(filename as zstring ptr, access_mode as zstring ptr) as FILE ptr | Open a file for buffered I/0.
fprintf(file_pointer as FILE ptr, format_string as zstring ptr, args) as integer | Write formatted output to a file,
fputc(c as integer, file_pointer as FILE ptr) as integer | Write a character to a stream.
fputchar(c as integer) as integer | Write a character to stdout.
fputs(string1 as zstring ptr, file_pointer as FILE ptr) as integer | Write a zstring to a stream.
fread(buffer as zstring ptr, size as size_t count as size_t, file_pointer as FILE ptr) as size_t | Read unformatted data from a stream into a buffer.
freopen(filename as zstring ptr, access as zstring ptr mode, file_pointer as FILE ptr) as FILE ptr | Reassign a file pointer to a different file.
fscanf(file_pointer as FILE ptr, format as zstring ptr zstring, args) as integer | Read formatted input from a stream.
fseek(file_pointer as FILE ptr, offset as long, origin as integer) as integer | Set current position in file to a new location.
fsetpos(file_pointer as FILE ptr, current_pos as fpos_t) as integer | Set current position in file to a new location.
ftell(file_pointer as FILE ptr) as long | Get current location in file.
fwrite(buffer as zstring ptr, size as size_t, count as size_t file_pointer as FILE ptr) as size_t | Write unformatted data from a buffer to a stream.
getc(file_pointer as FILE ptr) as integer | Read a character from a stream.
getchar() as integer | Read a character from stdin.
gets(buffer as zstring ptr) as zstring ptr | Read a line from stdin into a buffer.
printf(format as zstring ptr _string, args) as integer | Write formatted output to stdout.
putc(c as integer, file_pointer as FILE ptr) as integer | Write a character to a stream.
putchar(c as integer) as integer | Write a character to stdout.
puts(string1 as zstring ptr) as integer | Write a zstring to stdout.
rewind(file_pointer as FILE ptr) | Rewind a file.
scanf(format_string as zstring ptr, args) as integer | Read formatted input from stdin.
setbuf(file_pointer as FILE ptr, buffer as zstring ptr) | Set up a new buffer for the stream.
setvbuf(file_pointer as FILE ptr, buffer as zstring ptr, buf_type as integer, buf as size_t size) as integer | Set up new buffer and control the level of buffering on a stream.
sprintf(string1 as zstring ptr, format_string as zstring ptr, args) as integer | Write formatted output to a zstring.
sscanf(buffer as zstring ptr, format_string as zstring ptr, args) as integer | Read formatted input from a zstring.
tmpfile() as FILE ptr | Open a temporary file.
tmpnam(file_name as zstring ptr) as zstring ptr | Get temporary file name.
ungetc(c as integer, file_pointer as FILE ptr) as integer | Push back character into stream' s buffer

Low level I/O
`#include "crt/io.bi"`
So far Win32 only, connects to MSVCRT.DLL (headers missing for other platforms)

Prototype (with parameters) | Comments
_close(handle as integer) as integer | Close a file opened for unbuffered I/O.
_creat(filename as zstring ptr, pmode as integer) as integer | Create a new file with specified permission setting.
_eof(handle as integer) as integer | Check for end of file.
_lseek(handle as integer, offset as long, origin as integer) as long | Go to a specific position in a file.
_open(filename as zstring ptr, oflag as integer, pmode as uinteger) as integer | Open a file for low-level I/O.
_read(handle as integer, buffer as zstring ptr, length as uinteger) as integer | Read binary data from a file into a buffer.
_write(handle as integer, buffer as zstring ptr, count as uinteger) as integer | Write binary data from a buffer to a file.

Mathematics
`#include "crt/math.bi"`

Prototype (with parameters) | Comments
abs_(n as integer) as integer | Get absolute value of an integer.
acos_(x as double) as double | Compute arc cosine of x.
asin_(x as double) as double | Compute arc sine of x.
atan_(x as double) as double | Compute arc tangent of x.
atan2_(y as double, x as double) as double | Compute arc tangent of y/x.
ceil(x as double) as double | Get smallest integral value that exceeds x.
cos_(x as double) as double | Compute cosine of angle in radians.
cosh(x as double) as double | Compute the hyperbolic cosine of x.
div(number as integer, denom as integer) as div_t | Divide one integer by another.
exp_(x as double) as double | Compute exponential of x.
fabs(x as double) as double | Compute absolute value of x.
floor(x as double) as double | Get largest integral value less than x.
fmod(x as double, y as double) as double | Divide x by y with integral quotient and return remainder.
frexp(x as double, expptr as integer ptr) as double | Breaks down x into mantissa and exponent of no.
labs(n as long) as long | Find absolute value of long integer n.
ldexp(x as double, exp as integer) as double | Reconstructs x out of mantissa and exponent of two.
ldiv(number as long, denom as long) as ldiv_t | Divide one long integer by another.
log_(x as double) as double | Compute log(x).
log10(x as double) as double | Compute log to the base 10 of x.
modf(x as double, intptr as double ptr) as double | Breaks x into fractional and integer parts.
pow(x as double, y as double) as double | Compute x raised to the power y.
rand() as integer | Get a random integer between 0 and 32.
random(max_num as integer) as integer | Get a random integer between 0 and max_num.
randomize() | Set a random seed for the random number generator.
sin_(x as double) as double | Compute sine of angle in radians.
sinh(x as double) as double | Compute the hyperbolic sine of x.
sqrt(x as double) as double | Compute the square root of x.
srand(seed as uinteger) | Set a new seed for the random number generator (rand).
tan_(x as double) as double | Compute tangent of angle in radians.
tanh(x as double) as double | Compute the hyperbolic tangent of x.

Memory Allocation
`#include "crt/stdlib.bi"`

Prototype (with parameters) | Comments
calloc(num as size_t elems, elem_size as size_t) as any ptr | Allocate an array and initialise all elements to zero .
free(mem_address as any ptr) | Free a block of memory.
malloc(num as size_t bytes) as any ptr | Allocate a block of memory.
realloc(mem_address as any ptr, newsize as size_t) as any ptr | Reallocate (adjust size) a block of memory.

Process Control
`#include "crt/stdlib.bi"`

Prototype (with parameters) | Comments
abort() | Abort a process.
execl(path as zstring ptr, arg0 as zstring ptr, arg1 as zstring ptr,..., NULL) as integer | Launch a child process (pass command line).
execlp(path as zstring ptr, arg0 as zstring ptr, arg1 as zstring ptr,..., NULL) as integer | Launch child (use PATH, pass command line).
execv(path as zstring ptr, argv as zstring ptr) as integer | Launch child (pass argument vector).
execvp(path as zstring ptr, argv as zstring ptr) as integer | Launch child (use PATH, pass argument vector).
exit_(status as integer) | Terminate process after flushing all buffers.
getenv(varname as zstring ptr) as zstring ptr | Get definition of environment variable,
perror(string1 as zstring ptr) | Print error message corresponding to last system error.
putenv(envstring as zstring ptr) as integer | Insert new definition into environment table.
raise(signum as integer) as integer | Generate a C signal (exception).
system_(string1 as zstring ptr) as integer | Execute a resident operating system command.

Searching and Sorting
`#include "crt/stdlib.bi"`
Note: The compare callback function required by `bsearch` and `qsort` must be declared as `cdecl`. It must return a value <0 if its first argument should be located before the second one in the sorted array, >0 if the first argument should be located after the second one, and zero if their relative positions are indifferent (equal values).

Prototype (with parameters) | Comments
bsearch(key as any ptr, base as any ptr, num as size_t, width as size_t, compare as function(elem1 as any ptr, elem2 as any ptr) as integer) as any ptr | Perform binary search.
qsort(base as any ptr, num as size_t, width as size_t, compare as function(elem1 as any ptr, elem2 as any ptr) as integer) | Use the quicksort algorithm to sort an array.

String Manipulation
`#include "crt/string.bi"`

Prototype (with parameters) | Comments
stpcpy(dest as zstring ptr, src as zstring ptr) as zstring ptr | Copy one zstring into another.
strcmp(string1 as zstring ptr, string2 as zstring ptr) as integer | Compare string1 and string2 to determine alphabetic order.
strcpy(string1 as zstring ptr, string2 as zstring ptr) as zstring ptr | Copy string2 to string1.
strerror(errnum as integer) as zstring ptr | Get error message corresponding to specified error number.
strlen(string1 as zstring ptr) as integer | Determine the length of a zstring.
strncat(string1 as zstring ptr, string2 as zstring ptr, n as size_t) as zstring ptr | Append n characters from string2 to string1.
strncmp(string1 as zstring ptr, string2 as zstring ptr, n as size_t) as integer | Compare first n characters of two strings.
strncpy(string1 as zstring ptr, string2 as zstring ptr, n as size_t) as zstring ptr | Copy first n characters of string2 to string1.
strnset(string1 as zstring ptr, c as integer, size _t n) as zstring ptr | Set first n characters of zstring to c.
strrchr(string1 as zstring ptr, c as integer) as zstring ptr | Find last occurrence of character c in zstring.

Time
`#include "crt/time.bi"`

Prototype (with parameters) | Comments
asctime(time as type tm ptr) as zstring ptr | Convert time from type tm to zstring.
clock() as clock_t | Get elapsed processor time in clock ticks.
ctime(time as time_t ptr) as zstring ptr | Convert binary time to zstring.
difftime(time_t time2, time_t time1) as double | Compute the difference between two times in seconds.
gmtime(time as time_t ptr) as type tm ptr | Get Greenwich Mean Time (GMT) in a tm structure.
localtime(time as time_t ptr) as type tm ptr | Get the local time in a tm structure.
time_(timeptr as time_t ptr) as time_t | Get current time as seconds elapsed since 0 hours GMT 1/1/70.

See also

- `#include`