ANSI C Stdlib Library

The mikroC PRO for PIC32 provides a set of standard ANSI C library functions of general utility.

  Important :

Library Dependency Tree

C Stdlib Library Dependency Tree

Library Functions

abs

Prototype

int abs(int a);

Description

Function returns the absolute (i.e. positive) value of a.

Example
result = abs(-12);  // result = 12

atof

Prototype

double atof(char *s);

Description

Function converts the input string s into a double precision value and returns the value. Input string s should conform to the floating point literal format, with an optional whitespace at the beginning. The string will be processed one character at a time, until the function reaches a character which it doesn’t recognize (including a null character).

Example
doub = atof("-1.23");  // doub = -1.23

atoi

Prototype

int atoi(char *s);

Description

Function converts the input string s into an integer value and returns the value. The input string s should consist exclusively of decimal digits, with an optional whitespace and a sign at the beginning. The string will be processed one character at a time, until the function reaches a character which it doesn’t recognize (including a null character).

Example
result = atoi("32000");  // result = 32000

atol

Prototype

long atol(char *s);

Description

Function converts the input string s into a long integer value and returns the value. The input string s should consist exclusively of decimal digits, with an optional whitespace and a sign at the beginning. The string will be processed one character at a time, until the function reaches a character which it doesn’t recognize (including a null character).

Example
result = atol("-32560");  // result = -32560

div

Prototype

div_t div(int number, int denom);

Description

Function computes the result of division of the numerator number by the denominator denom; the function returns a structure of type div_t comprising quotient (quot) and remainder (rem), see Div Structures.

Example
dt = div(1234,100);

ldiv

Prototype

ldiv_t ldiv(long number, long denom);

Description

Function is similar to the div function, except that the arguments and result structure members all have type long.

Function computes the result of division of the numerator number by the denominator denom; the function returns a structure of type ldiv_t comprising quotient (quot) and remainder (rem), see Div Structures.

Example
dl = ldiv(-123456, 1000);

uldiv

Prototype

uldiv_t uldiv(unsigned long number, unsigned long denom);

Description

Function is similar to the div function, except that the arguments and result structure members all have type unsigned long.

Function computes the result of division of the numerator number by the denominator denom; the function returns a structure of type uldiv_t comprising quotient (quot) and remainder (rem), see Div Structures.

Example
dul = uldiv(123456,1000);

labs

Prototype

long labs(long x);

Description

Function returns the absolute (i.e. positive) value of long integer x.

Example
result = labs(-2147483647);

max

Prototype

int max(int a, int b);

Description

Function returns greater of the two integers, a and b.

Example
result = max(123,67);  // function returns 123

min

Prototype

int min(int a, int b);

Description

Function returns lower of the two integers, a and b.

Example
result = min(123,67);  // function returns 67

rand

Prototype

int rand();

Description

Function returns a sequence of pseudo-random numbers between 0 and 32767. The function will always produce the same sequence of numbers unless srand is called to seed the start point.

Example
while(1)
  result = rand()
   ;

srand

Prototype

void srand(unsigned x);

Description

Function uses x as a starting point for a new sequence of pseudo-random numbers to be returned by subsequent calls to rand. No values are returned by this function.

Example
srand(9);

xtoi

Prototype

unsigned xtoi(char *s);

Description

Function converts the input string s consisting of hexadecimal digits into an integer value. The input parameter s should consist exclusively of hexadecimal digits, with an optional whitespace and a sign at the beginning. The string will be processed one character at a time, until the function reaches a character which it doesn’t recognize (including a null character).

Example
result = xtoi("1FF");  // result = 511

Div Structures

Copy Code To ClipboardCopy Code To Clipboard
 typedef struct divstruct {
             int quot;
             int rem;
 } div_t;


 typedef struct ldivstruct {
             long quot;
             long rem;
 } ldiv_t;


 typedef struct uldivstruct {
             unsigned long quot;
             unsigned long rem;
 } uldiv_t;
Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code