我有这个:

typedef struct nodebase{
  char name[254];
  char sex;
  int  clientnum;
  int  cellphone;
  struct nodebase *next;
  struct nodebase *encoding;
} clientdata;

我在单独的函数中添加了clientdata *curr[];。我之所以将*curr改为*curr[]是因为这个客户机数据将存储在.txt文件中。所以我提出了一个单链表来读取所有的数据,当程序每5个变量fscanf时,我会加1到clientcounter
因此,*curr[]将是*curr[clientcounter]
现在,我需要将这个指针数组转换成名为temp[clientcounter]的char数组,因为char数组需要在后面的代码中计算其他值。
我想出了下面的代码:(在Windows上使用Tiny C)
void loaded_data_transfer(clientdata *curr,clientdata temp[],int clientcounter)
{
clientdata temp[] = {0};

temp[clientcounter].name = curr[clientcounter]->name;
temp[clientcounter].sex = curr[clientcounter]->sex;
temp[clientcounter].clientnum = curr[clientcounter]->clientnum;
temp[clientcounter].cellphone = curr[clientcounter]->cellphone;

}

问题是,Tiny C给了我一个错误:lvalue expectedtemp[clientcounter.name = ...部分。有人能告诉我我做错了什么吗?
如果有人知道一个更好的方法来跟踪客户数据的curr使用计数器和使用单一链接列表,请让我知道。

最佳答案

也许你想复制整个结构:

void loaded_data_transfer(clientdata * curr, clientdata temp[], int clientcounter)
{
    temp[clientcounter] = *curr; // Copy entire struct
}

它应该可以工作,因为您的结构没有任何指针成员。
我猜你是这样用的
clientdata * curr[CURR_SIZE];
clientdata temp[TEMP_SIZE];
/* init curr elements here */
loaded_data_transfer(*curr[clientcounter], temp, clientcounter);

07-24 09:45
查看更多