Dave's Brain

Browse - Programming Tips - How can I efficiently loop thru a constant array of strings?

Date: 2014apr8
Language: C/C++
Platform: Windows

Q.  How can I efficiently loop thru a constant array of strings?

A.  Here is a nice way do do that:

const LPCSTR things[] = { "One", "Two", Three", NULL }; // NULL terminated for (const LPCSTR *p = things; *p; p++) { printf("thing=%s\n", *p); // Use star-p }
This only works when you can define your own NULL-terminated array.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.