【发布时间】:2015-05-26 23:47:35
【问题描述】:
以下代码在倒数第二个语句中的箭头处给我一个错误。我不知道为什么会这样。谁能告诉我为什么?
我什至不知道从哪里开始。我认为这是正确的,但有一些问题。
/*
* File: newmain.c
* Author: user1
*
* Created on May 26, 2015, 4:30 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
/*
*
*/
#ifndef KEYTYPE
#define KEYTYPE char *
#endif
#ifndef VALUETYPE
#define VALUETYPE double
#endif
#ifndef TYPE
#define TYPE struct association
//# define TYPE int
#endif
struct association
{
KEYTYPE key;
VALUETYPE value;
};
struct DynArr
{
TYPE *data; /* pointer to the data array */
//struct association *data;
int size; /* Number of elements in the array */
int capacity; /* capacity ofthe array */
};
int main(int argc, char** argv) {
struct DynArr *da;
da = malloc(sizeof(struct DynArr));
assert(da!= 0);
da->capacity = 2;
da->data = malloc(sizeof(TYPE) * da->capacity);
assert(da->data != 0);
da->size = 0;
if(da->data[0]->key == 2) //test.c:58:10: error: invalid type argument of ‘->’ (have ‘struct DynArr’) <<<<<<<<<<<<<<<<<<
return (EXIT_SUCCESS);
}
【问题讨论】:
-
你键盘上的
typedef按钮坏了吗?