I need to assign an array of 6 arrays and it's from 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)
}
In CodeBlocks it compiles with no errors , in VS2010 it doesn't and these are the 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 overall
You need to use pointers (they are tricky in C). Try the following code (I've added some debug, so change it back to 0's):
#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
}
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.