Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

514
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda