Length of an array and pointer in c

0
char *nombre_carrera[] = {"perro prueba0", "perro prueba1", "perro prueba2",...........};

How can I know the length of the arrangement to know how many perro prueba there is?

I used strlen(*nombre_carrera) but it gives me the length of "perro prueba0" only and if I put strlen(**nombre_carrera) or strlen(nombre_carrera) gives error

    
asked by EmiliOrtega 28.08.2017 в 03:52
source

1 answer

2

If you want to know how many elements the array has, you have to use the sizeof in C, The sizeof operator provides the amount of storage, in bytes, needed to store an object of the operand type. This operator allows you not to have to specify data sizes dependent on the equipment in the programs.

 #include <iostream>
    using namespace std;
    int main()
    {
    char *nombre_carrera[] = {"perro prueba1", "perro prueba10", "perro prueba200", "Perro"};
    int resul = sizeof(nombre_carrera)/sizeof(char*);
    printf("Tiene: %i", resul);
    }
    
answered by 28.08.2017 / 04:42
source