Example, Strrchr( ) function, Syntax – Echelon Neuron C User Manual

Page 162: Swap_bytes( ) built-in function

Advertising
background image

142

Functions

Example

#include <string.h>

char s[20];

void f(char *p)
{

strncpy(s, p, 19);

// Prevent overflow

s[19] = '\0'; // Force termination

}

strrchr( )

Function

The strrchr( ) function scans a string for the last occurrence of a given character.
The function scans a string in the reverse direction (hence the extra ‘r’ in the

name of the function), looking for a specific character. The strrchr( ) function

finds the last occurrence of the character

c

in string

s

. The NUL ('\0') terminator

is considered to be part of the string. The return value is a pointer to the

character found, otherwise null. See also strcat( ), strchr( ), strcmp( ), strcpy( ),

strlen( ), strncat( ), strncmp( ), and strncpy( ).

Syntax

#include <string.h>

char *strrchr (const char *

s

, char

c

);

Example

#include <string.h>

void f(void)
{
char

buf[20];

char

*p;


strcpy(buf, "Hello World");

p = strrchr(buf, 'o');

// Assigns &(buf[7]) to p

p = strrchr(buf, '\0');

// Assigns &(buf[11]) to p

p = strrchr(buf, 'x');

// Assigns NULL to p

}

swap_bytes( )

Built-in Function

The swap_bytes( ) built-in function returns the byte-swapped value of

a

. See also

high_byte( ), low_byte( ), and make_long( ).

Syntax

unsigned long swap_bytes (unsigned long

a

);

Advertising