Skip to content

Instantly share code, notes, and snippets.

@lesovsky
Created January 7, 2017 19:42
Show Gist options
  • Select an option

  • Save lesovsky/56c44ee9707773d4d6e7e55a8f16efdf to your computer and use it in GitHub Desktop.

Select an option

Save lesovsky/56c44ee9707773d4d6e7e55a8f16efdf to your computer and use it in GitHub Desktop.
Using pointer to strings array.
/* This example used in the following scenario:
* 1. there are several sets of files.
* 2. we need to choose specific set.
* 3. handle files from this set in the loop.
*/
#include<stdio.h>
int main()
{
int i;
char *set_a[4] = { "C", "C++", "Java", "VBA" };
char *set_b[4] = { "Tea", "Cofee", "Water", "Oil" };
char *set_c[4] = { "Earth", "Venus", "Mercury", "Mars" };
char *(*ptr)[4]; // = &arr;
/* here is the logic for choosing set */
ptr = &set_b;
for(i = 0; i < 4; i++)
printf("String %d : %s\n",i+1,(*ptr)[i]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment