Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

515
Visualizações
How to loop through double pointers without knowing size. (C)

How can I loop through this double pointer without knowing it's size.

char *arr[] = {"ant", "bat", "cat", "dog", "egg", "fly"}; 
char **ptr = arr; // Double pointer 

I tried this but I get an error

while (*ptr){
   printf("%s\n",*ptr);
   ptr+=1;
}

I wan't something similar to this but with double pointers.

char *word = *ptr;
for (int i = 0; *(word + i) != '\0'; i++)
{
   printf("%c", *(word + i));
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The reason you can determine the end of a string with \0 is because when you assign one to a pointer a null byte is automatically placed at the end, note that the definition of string is a null terminated array of characters. You can mimic this behavior in an array of strings by adding a NULL element at the end:

char *arr[] = {"ant", "bat", "cat", "dog", "egg", "fly", NULL};
char **ptr = arr;  // Double pointer

while (*ptr) {
    printf("%s\n", *ptr);
    ptr += 1;
}

This is what is called a sentinel.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda