CPowerC Functions ----------------- -------------------------------------- abs, fabs - absolute value abs(i) int i; fabs(f) float f; abs and fabs return the absolute value of their arguments -------------------------------------- atoi, atof - convert strings to numbers atoi(iptr) char *iptr; float atof(fptr) char *fptr; atoi converts the string pointed to by its argument into an integer atof converts the string pointed to by its argument into a float quantity both functions ignore leading spaces --------------------------------------- bcmp, bcopy, bzero, ffs - bit and byte string functions bcmp(p1, p2, len) char *p1, *p2; bcopy(p1, p2, len) char *p1, *p2; ffs(i) int i; bcmp compares len bytes of the strings p1 and p2 and returns zero if they are the same, none-zero otherwise bcopy copies len bytes from string p1 to string p2 bzero fills string p with len zeros ffs returns the position of the first set bit in its argument. bits are numbered starting at one. if the argument is zero ffs returns -1 -------------------------------------- exit, abort - terminate execution exit() abort() exit and abort end program execution. all files opened by fopen are closed -------------------------------------- exp, log, log10, pow, sqrt - assorted math functions #include <math.h> float exp(x) float x; float log(x) float x; float log10(x) float x; float pow(x, y) float x, y; float sqrt(x) float x; exp returns e**x log returns the natural logarithm of x log10 returns base 10 logarithm of x pow returns x**y. sqrt returns the square root of x -------------------------------------- ferror - check for error feof - check for end of file #include <stdio.h> ferror() feof(stream) FILE stream; ferror returns non-zero if an error occurred during the last disk operation, zero otherwise feof returns non-zero if the specified stream has reached end of file, zero otherwise -------------------------------------- floor, ceil, modf - get integer part of float #include <math.h> float floor(x) float x; float ceil(x) float x; float modf(x,ptr) float x, *ptr; floor returns the greatest integer not greater than x ceil returns the least integer not less than x modf returns the positive fractional part of x and stores the integer part indirectly through ptr -------------------------------------- fopen, freopen, fclose - open disk file for i/o #include <stdio.h> FILE fopen(filename,mode) char *filename,*mode; FILE freopen(filename,mode,stream) char *filename,*mode; FILE stream; fclose(stream) FILE stream; fopen opens a disk file file for reading or writing. the string filename contains the name of the file and the first character of the string mode specifies read or write ('r' or 'w'). the default file type is sequential, but program file types may selected. fopen returns a file number (hearafter referred to as a stream) which may be used in later i/o, or it returns zero if the file cannot be opened freopen opens a file much the same as fopen does. the file stream is first closed, then if successful the old stream is assigned to the new file. this is useful to assign the constant streams stdin and stdout to disk files ferror should be checked after every fopen fclose closes the specified file -------------------------------------- fread, fwrite - array input/output #include <stdio.h> fread(ptr,elsize,nelem,stream) char *ptr; FILE stream; fwrite(ptr,elsize,nelem,stream) char *ptr; FILE stream; Fread/fwrite reads/writes an array containing nelem elements each of size elesize bytes geginning at ptr from/to the specified stream fread returns zero upon end of file -------------------------------------- frexp,ldexp - split float into mantissa and exponent float frexp(value,ptr) float value; int *ptr; float ldexp(value,exp) float value; frexp splits value into a mantissa m of manitude less than 1 (which is returned) and an exponent exp (which is stored indirectly through ptr) such that value = m * 2**exp ldexp returns value * 2**exp -------------------------------------- getc,getchar,fgetc,getw - input character or integer #include <stdio.h> int getc(stream) FILE stream; int getchar() int fgetc(stream) FILE stream; int getw(stream) FILE stream; Getc and fgetc read a character from the specified stream Getchar reads a character from the standard input Getw reads an integer (two bytes) from the specified stream All of these functions return EOF upon end of file, however, since EOF is a valid integer, feof should be used to check for end of file after getw -------------------------------------- gets, fgets - input a string #include <stdio.h> char *gets(s) char *s; char *fgets(s,n,stream) char *s; FILE stream; Gets inputs a string from the standard input. it reads characters into s until a newline is encountered. the newline is replaced with a zero Fgets inputs a string from the specified stream. it reads n-1 characters or until a newline is encountered whichever comes first. the newline is not replaced but a zero is placed after the last character read Both functions return s upon normal completion or NULL upon end of file -------------------------------------- highmem - memory configuration highmem(address) unsigned address; Highmem sets the highest address that a C program can use. the run time stack will not go past this address, and the memory allocation functions (malloc, calloc, realloc) will not allocate memory higher than this address. the value of the argument must be one greater than the desired address. if highmem is not called, address defaults to 0xd000, which means the highest address which can be used is 0xcfff -------------------------------------- hypot, cabs - calculate hypotenuse #include <math.h> float hypot(x,y) float x, y; float cabs(c) struct (* float x,y; *) *c; Hypot and cabs return sqrt(x*x + y*y) -------------------------------------- isalpha, ... - classify characters isalpha(c) The following functions return non-zero integers if the stated condition is true, zero otherwise isalpha c is a letter isupper c is an upper case letter islower c is a lower case letter isdigit c is a digit isalnum c is a letter or a digit isspace c is a space or a newline ispunct c is a punctuation char isprint c is a printable char iscntrl c is a control char isascii c has value less than 0200 -------------------------------------- malloc, calloc, realloc,free - memory allocation char *malloc(size) unsigned size; char *calloc(nelem, elsize) unsigned nelem, elsize; char *realloc(ptr, size) char *ptr; unsigned size; free(ptr) char *ptr; Malloc returns a pointer to a block of memory containing at least size bytes Calloc returns a pointer to a block of zero-filled memory containing at least nelem * elsize bytes Realloc copies the block pointed to by ptr into a new block containing at least size bytes. ptr must point to a block allocated by malloc, calloc or realloc free releases the block pointed to by ptr into the free memory list Malloc, calloc and realloc all return the null pointer (0) if there is not enough free memory to satisfy the request -------------------------------------- open, close - BASIC style open/close open(fileno, device, secaddr, name) char *name; close(fileno); The arguments of open correspond exactly to the file number, device number, secondary address, and file name arguments of the BASIC OPEN command. consult a Commodore 64 manual for the meanings of the arguments. similarly, close corresponds to the BASIC CLOSE command. open returns zero if the file can't be checked after opening a write file The file number argument may be used any place a stream (ie. a value returned by fopen) is used. File numbers 1 through 4 are reserved for system use. if open and fopen are used at the same time file numbers passed to open should be limited to the range 5 through 9 -------------------------------------- opendir, readdir, rewinddir closedir - directory functions #include <dir.h> opendir(unit:) struct direct *readdir() rewinddir() closedir() Opendir opens a disk directory for reading. the unit from which the directory is to be read may be specified. if the directory can't be opened NULL is returned. NOTE: the directory functions do not apply to the RAMDISK. Readdir reads the next directory entry and returns a pointer to it. if there are no more entries NULL is rteturned. see the header file dir.h and the VIC-1541 User's Manual for the format of a directory entry Rewinddir causes readdir to read the first entry upon the next call Closedir closes the directory. -------------------------------------- (for Commodore 128) open2() - BASIC style open to unit# open2(name, filename, unit, channel) char *name; int filenum; char unit; int channel; open2() is the same as open(), except that the disk drive is specified by a unit number rather than a device number. if "filename" is not empty, then the unit number is taken from there, otherwise it is taken from "unit" -------------------------------------- (for Commodore 128) peek() - BASIC style peek() peek(bank, address); unsigned bank, address; peek() returns the contents of the memory location in "bank" at "address" -------------------------------------- (for Commodore 128) poke() - BASIC style poke poke(bank, address, value) unsigned bank, address, value; poke() puts the byte "value" into the memory locatin specified by "bank" and "address" -------------------------------------- printf, fprintf, sprintf - formatted output #include <stdio.h> printf(control [, arg] ...) char *control; fprintf(stream, control, [, arg] ...) FILE stream; char *control; spri...
Amiga7878