Initialization error in VS2010 during array initialization

I need to assign an array of 6 arrays and its type set[maxSetLength]

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#define maxSetLength 129

typedef short int set[maxSetLength]; 

int _tmain(int argc, _TCHAR* argv[]){
int i;
set a={0},b={0},c={0},d={0},e={0},f={0}; // Assigning 6 Sets (Arrays) initialized by zeros
set sets[6]={a,b,c,d,e,f}; //Inserting All Sets into one Array (Array Of Arrays)
}

CodeBlocks compiles without errors; in VS2010, this is not so, and these are errors:

6 times

error C2440: 'initializing' : cannot convert from 'set' to 'short'

6 times

IntelliSense: a value of type "short *" cannot be used to initialize an entity of type "short"

12 Errors in general

+3
source share
2 answers

You need to use pointers (they are complex in C). Try the following code (I added some debugs, so change them to 0):

#include <stdio.h>
#include <string.h>

#define maxSetLength 129

typedef short int set[maxSetLength]; 

main()
{

int i;
set a={55},b={0},c={0},d={0},e={0},f={66}; // Assigning 6 Sets (Arrays) initialized by zeros
set sets[6]={*a,*b,*c,*d,*e,*f};

printf("%d\n", sets[0][0]);   // should be 55
printf("%d\n", sets[0][5]);   // should be 66

}
0
source
set a={0},b={0},c={0},d={0},e={0},f={0}; // Assigning 6 Sets (Arrays) initialized by zeros
set *sets[6]={&a, &b, &c, &d, &e, &f}; //Inserting All Sets into one Array (Array Of Arrays)
0
source

All Articles