Espaços nominais
Variantes
Acções

strstr

Da cppreference.com
< c‎ | string‎ | byte

 
 
 
Cordas de terminação nula de bytes
Funções
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Manipulação personagem
Original:
Character manipulation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Conversões para formatos numéricos
Original:
Conversions to numeric formats
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Manipulação de cadeia
Original:
String manipulation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
strcpy
strncpy
strcat
strncat
strxfrm
Exame String
Original:
String examination
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Manipulação de memória
Original:
Memory manipulation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
memchr
memcmp
memset
memcpy
memmove
Diversos
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
strerror
 
Defined in header <string.h>
const char *strstr( const char* str, const char* substr );
      char strstr(        char* str, const char* substr );
Encontra a primeira ocorrência do substr cadeia de bytes na cadeia de bytes apontado por str.
Original:
Finds the first occurrence of the byte string substr in the byte string pointed to by str.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Índice

[editar] Parâmetros

str -
ponteiro para o byte string terminada em nulo para examinar
Original:
pointer to the null-terminated byte string to examine
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
substr -
ponteiro para o byte string terminada em nulo para pesquisar
Original:
pointer to the null-terminated byte string to search for
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Valor de retorno

Ponteiro para o primeiro caractere da substring encontrada em str, ou se não NULL substring for encontrado. Se substr aponta para uma cadeia vazia, str é devolvido.
Original:
Pointer to the first character of the found substring in str, or NULL if no such substring is found. If substr points to an empty string, str is returned.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Exemplo

#include <string.h>
#include <stdio.h>
 
void find_str(char const* str, char const* substr) 
{
    char* pos = strstr(str, substr);
    if(pos) {
        printf("found the string '%s' in '%s' at position: %d\n", substr, str, pos - str);
    } else {
        printf("the string '%s' was not found in '%s'\n", substr, str);
    }
}
 
int main(int argc, char* argv[]) 
{
    char* str = "one two three";
    find_str(str, "two");
    find_str(str, "");
    find_str(str, "nine");
    find_str(str, "n");
 
    return 0;
}

Output:

found the string 'two' in 'one two three' at position: 4
found the string '' in 'one two three' at position: 0
the string 'nine' was not found in 'one two three'
found the string 'n' in 'one two three' at position: 1

[editar] Veja também

encontra a primeira ocorrência de um caractere
Original:
finds the first occurrence of a character
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(função) [edit]
localiza a última ocorrência de um caractere
Original:
finds the last occurrence of a character
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(função) [edit]