c - How to init a member with specific value in a static structure array of configurable count? -


this question has answer here:

struct move { int left; int right; int up; int down; };  struct move moves[config_variable_x]; 

number of moves array configuration variable, can set value developer.

now, moves[x].right alone should inited value 1. know can write funciton , loop through , init right member 1, there way init particular value in definition above?

hope helps you.

#include <stdio.h> #define max 8  struct move { int left; int right; int up; int down; };  int main() {         struct move moves[max]={[0 ... max-1].right = 1};          printf("...%d\n",moves[0].left);         printf("...%d\n",moves[1].right);         printf("...%d\n",moves[2].right);         printf("...%d\n",moves[3].right);         printf("...%d\n",moves[4].right);         printf("...%d\n",moves[5].right);         printf("...%d\n",moves[6].right);         printf("...%d\n",moves[7].right);         return 0; } 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -