Echelon Neuron C Manual do Utilizador Página 158

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 267
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 157
138 Functions
strchr( ) Function
The strchr( ) function searches the string
s
for the first occurrence of the
character
c
. If the string does not contain
c
, the strchr( ) function returns the
null pointer. The NUL character terminator ('\0') is considered to be part of the
string, thus strchr(s,'\0') returns a pointer to the NUL terminator. See also
strcat( ), strcmp( ), strcpy( ), strlen( ), strncat( ), strncmp( ), strncpy( ), and
strrchr( ).
Syntax
#include <string.h>
char *strchr (const char *
s
, char
c
);
Example
#include <string.h>
void f(void)
{
char buf[20];
char *p;
strcpy(buf, "Hello World");
p = strchr(buf, 'o'); // Assigns &(buf[4]) to p
p = strchr(buf, '\0'); // Assigns &(buf[11]) to p
p = strchr(buf, 'x'); // Assigns NULL to p
}
strcmp( ) Function
The strcmp( ) function compares the contents of the
s1
and
s2
strings, up to the
NUL terminator character in the shorter string. The function performs a case-
sensitive comparison. If the strings match identically, 0 is returned. When a
mismatch occurs, the characters from both strings at the mismatch are
compared. If the first string’s character is greater using an unsigned comparison,
the return value is positive. If the second string's character is greater, the return
value is negative.
The terminating NUL ('\0') character is compared just as any other character.
See also strcat( ), strchr( ), strcpy( ), strlen( ), strncat( ), strncmp( ), strncpy( ),
and strrchr( ).
Syntax
#include <string.h>
int strcmp (const unsigned char *
s1
, const unsigned char *
s2
);
Example
#include <string.h>
void f(void)
Vista de página 157
1 2 ... 153 154 155 156 157 158 159 160 161 162 163 ... 266 267

Comentários a estes Manuais

Sem comentários