jeudi 17 août 2017

How to iterate through const char** variable

I want to iterate through a const char** variable.

auto temp = ReturnCharPointer();//This method return const char**

This pointer consists of two strings 0-"John", 1-"David".

When I trying iterate through it I am getting exception as violating access for reading.

for(int i=0; temp[i] != NULL; i++)
{
   printf(temp[i]);//once i's position is 2 that is no data is there, it is 
                   //throwing exception
}

How can I prevent it from throwing exception.

Aucun commentaire:

Enregistrer un commentaire