我需要分配一个由6个数组组成的数组,它来自类型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中它的编译没有错误,在VS2010中它没有错误,以下是错误:
6次
error C2440: 'initializing' : cannot convert from 'set' to 'short'6次
IntelliSense: a value of type "short *" cannot be used to initialize an entity of type "short"总共12个错误
发布于 2014-02-05 11:35:16
你需要使用指针(它们在C中很棘手)。尝试下面的代码(我已经添加了一些调试,所以将它改回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
}发布于 2014-02-05 17:14:08
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)https://stackoverflow.com/questions/21567978
复制相似问题