我在使用指针时如何分配信息时遇到了麻烦。
我无法在readName
函数中分配任何值。你能检查一下我是否正确地分配了结构吗?或者是否有另一种方法可以在不改变打击和功能参数的情况下做到这一点?
typedef struct name
{
char info[];
int number;
//some more codes
} name;
typedef struct Data
{
name ** n;
//some more codes
} Data;
int readName(FILE *const fp, name **const names)
{
(*names)->number = 1; // no idea what to put here to store
strcat ((*names)->info, "aBC");
//codes
}
int read(FILE *const fp, Data *const data)
{
data->n = malloc(sizeof(name*)*1); // am I mallocing correctly?
data->n[0]=malloc(sizeof(name));
i = readName(fp, &data->n[Data->n]);
//codes
}
int main ()
{
Data * d;
d = malloc (sizeof (Data));
i = read(fp, d); //assume fp is decleared
//codes that usses the struct
}